Form data is empty while posting form through ajax using jquery in WordPress

Try using .serialize() instead of FormData function step1SaveData(){ var formData = jQuery(‘#tpform1′).serialize(); console.log(formData); jQuery.ajax({ type:”POST”, url:’http://lexem.in/wp-admin/admin-ajax.php’, data:{ action:’tpartners’, formdata:formData, }, success:function(data){ var insertedID = data.trim(); if(insertedID!=’fail’){ }else{ console.log(‘fail’); } } }); } or use .serializeArray() if you want your data in an array instead of a string. EDIT – from the comments, remove processData:false and … Read more

Updating User Profile with AJAX not working

This whole thing works as far as I can tell. In the future it may be easier to debug things by using PHP error_log() to write to the debug.log at certain points, like inside your ajax callback. If you’re only wanting to run this ajax for logged in users, you can drop the wp_ajax_nopriv hook … Read more

WooCommerce add_to_cart url not working [closed]

So I ended up making a workaround because I still have no clue what’s happening. I changed the url to point to the product page and I’m using ol’good PHP to get the values and add the product with WooCommerce API. Here’s my code: if(isset($_GET[‘order’]) && $_GET[‘order’] == ‘true’) { $typo = isset($_GET[‘attribute_pa_typographie’]) ? $_GET[‘attribute_pa_typographie’] … Read more

WordPress AJAX Call Not Return Result

There’s two problems: You’re not sending the AJAX request to the correct URL. You’re using PHP-style concatenation instead of JavaScript. For the first issue, a relative URL “admin-ajax.php” is not going to work. If you are on a page like /about-us/ then jQuery is going to send the request to /about-us/admin-ajax.php, which doesn’t exist. The … Read more

admin-ajax.php mixed content

You shouldn’t do something like this in your JS code: url: ‘https://’+window.location.host+’/admin/admin-ajax.php’, You should use wp_localize_script and pass proper URL in there. Let’s say your AJAX call is located in file my-js-file.js. Somewhere in your theme/plugin you have something like this wp_enqueue_script( ‘<SOME_HANDLE>’, … . ‘my-js-file.js’ , …); You should add this after it: wp_localize_script( … Read more

WP /wp-admin/admin-ajax.php produces 404

Your /wp-admin/admin-ajax.php might have been modified by another php file or plugin. Try downloading a copy of your wordpress version and overwrite admin-ajax.php with the original source file. If that doesn’t work, try deactivating your plugins (or theme) one by one until you notice a difference.

Problem with WordPress Ajax form

Ok, after a lengthy discussion Edegist and I actually sorted this all out. Here’s a couple of the key factors that comprise the solution. One, we had to loop through all of the selected checkboxes to pass via AJAX. jQuery( document ).ready( function( $ ) { $( ‘.kvo_ajax_submit_button’ ).click( function( e ) { e.preventDefault(); var … Read more

AJAX action not triggering PHP function

The problem is with the AJAX endpoint URL, i.e. url: userimg.ajax_url, which is not actually defined in your JS/PHP code. More specifically, you did define the correct URL, but in the JS object, the property name is ajaxurl and not ajax_url: // wrapped for brevity wp_localize_script( ‘ajax-account’, ‘userimg’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’, ‘relataive’ ) … Read more