WP AJAX API with JS file

Currently I’m assuming that is is backend (front end is slightly different), but it’s very easy to implement on the frontend if required. You are correct in thinking that because you haven’t used the WordPress admin-ajax.php file, all the goodness of WordPress is missing. Fortunately this is easily fixed. Before continuing I recommend that you … Read more

Search query with Ajax

This is a javascript issue. You have to prevent form submission to stop the page from reloading. See event.preventDefault() in jQuery docs. jQuery(“#Submityourskill”).click(function(event){ event.preventDefault(); // the rest of your code });

WordPress Insert not working with ajax

Your AJAX callback method should be outputting something followed by a die() statement. function wp_insert() { ..your code echo $whatever_your_results_are; // die(); } I would also recommend against prefixing your custom methods with wp_. That should be reserved for WordPress and will cause confusion to other developers – and probably you 6 months down the … Read more

click event to unhide something after ajax not firing

Your button was added dynamically. So you can not bind event in simple way. As button is added after DOM is fully ready. You need to bind it with the refrence of document or body jQuery(document).on(‘click’, ‘#readmore’, function(e){ e.preventDefault(); alert(“you clicked the button”); jQuery(“#bodytext”).css(“display”, “block”); }); Read more about it here

Ajax call through admin-ajax.php returns 404 error

success and error are functions, not properties of AJAX function. Working code: $(“.tabs .btn”).click(function(e) { e.preventDefault(); $.ajax({ url:”/wp-admin/admin-ajax.php”, type: “GET”, dataType: “html”, cache: false, data: { action: “shows” } }) .success(function(resp) { $(“.ajax-show”).append(resp); }) .error(function(xhr, status, error) { var err = JSON.parse(xhr.responseText); console.log(err); }); }); Also that should be noted: Deprecation Notice: The jqXHR.success(), jqXHR.error(), … Read more

Null/undefined return in WordPress AJAX request

I am not sure the output you have provided is the correct one but do you notice the ‘0’ character at the end of your string? {“title”:”R=3+”,”dates”:[“06\/04\/2014″,”11\/05\/2014″,”15\/06\/2014″,”27\/07\/2014″,”17\/08\/2014″,”28\/09\/2014″,”05\/10\/2014″,”19\/10\/2014″,”09\/11\/2014″,”23\/11\/2014″,”14\/12\/2014″],”series”:[{“data”:[[1396738800000,284],[1399762800000,350],[1402786800000,212],[1406415600000,296],[1408230000000,220],[1411858800000,253],[1412463600000,200],[1413673200000,310],[1415491200000,180],[1416700800000,156],[1418515200000,290]],”name”:”Bulls”}]}0 That is enough to cause the JSON parser to fail. Also, don’t use the contentType property like that since you don’t send any JSON, you should remove that … Read more

jQuery(selector) vs. $(selector)

This is because of jQuery noConflict wrappers. It is certainly not an oversight by WordPress developers; but rather, a great little way to ensure we (developers) can hook our own javascript files or libraries without conflicting with other javascript code. Be sure to read the Codex on jQuery noConflict Wrappers. The usage pretty much depends … Read more