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

Can’t add classes using jQuery from a JSON string with get_body_class()

get_body_class() is going to return an array of classes, which is then (per code not published in your question) JSON encoded into that comma separated string. While you can manipulate that in JavaScript, the easiest thing to do is implode the string before encoding: $c = get_body_class(‘project’); $c = implode($c,’ ‘); You should have a … Read more

PHP session when called wp_ajax_nopriv

WordPress does not use or affect PHP Sessions in any way. Therefore, the session functions will work exactly the same whether you’re using WordPress or plain PHP or AJAX requests or anything else. However, PHP Sessions depend very heavily on your specific PHP configuration. If you don’t have the PHP Session settings configured correctly in … Read more

Call Ajax URL in Plugin

Put below code in _construct() function and change action name to get_product_serial_callback :- add_action( ‘wp_ajax_get_product_serial_callback’, array($this,’get_product_serial_callback’) ); add_action( ‘wp_ajax_nopriv_get_product_serial_callback’, array($this,’get_product_serial_callback’ ));

Run javascript upon successfully set featured image

You could use .ajaxComplete, as mentioned by @onetrickpony in https://wordpress.stackexchange.com/a/36597/57034, except do it globally on document, as mentioned in http://api.jquery.com/ajaxcomplete/, then filter based on action: add_action( ‘admin_print_footer_scripts’, function () { ?> <script type=”text/javascript”> jQuery(function ($) { $(document).ajaxComplete(function (event, xhr, settings) { var match; if (typeof settings.data === ‘string’ && /action=set-post-thumbnail/.test(settings.data) && xhr.responseJSON && typeof xhr.responseJSON.data … Read more

Ajax not working for certain user roles

OK I found the issue. When directly entering myurl/wp-admin/admin-ajax.php?action= mdjm_update_addon_options into my browser window whilst logged in as an Administrator, I was getting the expected response of 0. However, when not logged in, or logged in as a non-admin, I noticed I was receiving “You do not have sufficient permissions to access this page”. Looking … Read more