Custom AJAX form not working async

First probable issue: You’re using name in the form. You should not, since it’s a reserved term in WordPress. Second probable issue: You’re using a form action URL of <?php echo get_template_directory_uri(); ?>/assets/php/process-contact.php. That will break if you use any WordPress functions (or functions defined in functions.php and plugins). This is the correct way to … Read more

How to get setting from separate file?

Simple answer: Don’t add a separate PHP file for AJAX requests. Declare the functions that will be used in your plugin and load them via admin-ajax.php. add_action(‘wp_ajax_custom_action_name’,’custom_action_handler’); // to make AJAX action available for non-logged in users: add_action(‘wp_ajax_nopriv_custom_action_name’,’custom_action_handler’); function custom_action_handler() { global $wpdb; // optionally keep the actual functions separately // include(dirname(__FILE__).’/ajax-handler.php’); // custom_ajax_handler_process(); // … Read more

Email Exists ERROR into Ajax registration form

Why are you making work hard for yourself? wp_create_user already checks if the email/login exists, which is also why your code is “failing” – $user_id will already be a WP_Error, so your elseif ( is_wp_error( $newerrors ) ) never fires. All you need is: $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email, $capa ); if ( is_wp_error( … Read more

Convert canvas to image and upload image to server

Since the file you send is base64 encoded, you will need to decode and save the result into a file at a temp directory. From there it is just a normal server side wordpress image manipulation and insertion of the relevant info into the DB, something that there are many examples for on this site. … Read more

Redirect wp_dropdown_pages() to an AJax request?

The following is the solution I came up with: <div id=”selection1″> <div id=”dropdown1″> <form id=”choice1″ action=”<?php bloginfo(‘url’); ?>” method=”get”> <?php $select = wp_dropdown_pages( array( ‘post_type’ => ‘page’, ‘show_option_none’ => ‘Select Car’, ‘echo’ => 0 ) ); echo $select; ?> </form> </div> <div id=”firstchoice”></div> </div> <script> $(‘#choice1’).change(function(){ //if the select value gets changed var png = … Read more

Simple jQuery AJAX Request fails to run PHP Script

A simple answer to your question is that you have the data type as JSON in your ajax request and you are passing a string in it. You need to pass a json object in the ajax request when you chose dataType equals to JSON. A JSON object is typically a key pair value inside … Read more

Redirect after saving form; and yet use wp_die()

Simply, you can not redirect the user from the sever in a Ajax callback. The redirect in the Ajax callback redirecta the Ajax request itself, it doesn’t redirect the user to a new location. I hope you understand what I mean. Remember that Ajax, by definition, is asynchronous. So, you need to think in another … Read more

No Object Properties sending form through AJAX

You can try to use new FormData() instead of new FormData($(‘form#change-avatar’)[0]). Also, after processData:false you should add contentType: false since jQuery will set it incorrectly otherwise, and for url, instead of ajaxurl you should useajaxobject.ajaxurl, since with wp_localize_script, the second parameter is the javascript object name