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

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

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

Conditional Ajax inclusion

When you call admin-ajax.php no query is being produced so is_page() or is_category() or any query based conditional tag will never return true. A better way would be to include your files inside the ajax callback, meaning something like this: add_action(‘wp_ajax_PAGE_ONLY_ACTION’,’PAGE_ONLY_Function’); function PAGE_ONLY_Function(){ include TEMPLATEPATH . ‘/ajaxLoops/ajax-open_client_editform.php’; /** * do your page only ajax */ … Read more