Why can wordpress not find the actions I add in my constructor?

Your constructor runs on the request from which you make the AJAX request, but not within the request that processes that AJAX request. The request that initially loads the page, and the AJAX request are two separate requests with no preservation of state between the two. This is not unique to WordPress, this is how … Read more

How to load wordpress sidebar using AJAX [duplicate]

Just go ahead and use a CSS media query to set the sidebar to display: none if the screen is too small, and provide your mobile users with some JavaScript that lets them selectively view it if they want to. Don’t worry about the loss in bit-and-cycle efficiency this causes; assuming that you get no … Read more

Closing ajax function file with die() causes error and empty page

The die should be in your show_article() function. Yours is out, so the whole script is terminated. Your function should be: function show_article(){ $q = $_GET[‘getid’]; echo strval($q); die; } or function show_article(){ $q = $_GET[‘getid’]; exit( strval($q) ); }

wp_localize_script not create variable in head section

Your code looks correct. alert(wp_ajax.nonce); should display the nonce. You can also verify the existence of the wp_ajax object via console.log(wp_ajax) in your browser’s Javascript console. wp_localize_script adds the object(s) to the footer (a call to wp_footer() should be present in the theme’s footer.php file). It’ll look like so: <script type=”text/javascript”> /* <![CDATA[ */ var … Read more

Ajax Form seems to post, but does not return

Your settings object in ajax call is not properly set up: action should be inserted in the data object. For example: $.ajax({ url: ajax_url, data:{ action: ‘trailer_report’,// action must be set here // other stuff here } //other ajax stuff }); Hope it helps!