Tag Info

Hot answers tagged

2

I finally got it. First mistake was to process the same function twice. I've called it once after the function and one more time in ajax action. So when using the ajax call, the function got executed twice. In the example from the OP, this is not a problem at all, because it is simplified to do only one thing, but in my real code it does much more and can ...


2

As for your PHP not being executed - the action parameter in your JavaScript AJAX call needs to match the hook name in your add_action call. Take a look at the example below. I haven't tested it but it should work. I have simplifed the AJAX call, feel free to modify it to suit your use case. var data = { action: 'jk-author-follow', // Look Ma' I talk to ...


2

Use check_ajax_referer: https://codex.wordpress.org/Function_Reference/check_ajax_referer //Check nonce if ( !check_ajax_referer( 'nonce-action-name', '_wpnonce', false ) ){ echo __('Ajax Security Check', 'yourtextdomain'); die(); }


1

The problem is that about.php is not a recognized file by WordPress and won't load any of the actual WordPress functions. <?php wp_header(); ?> in your themes header.php file actually loads most the WordPress functionality that you're used to using. Since you're not calling either get_header() OR wp_header() in your about.php file you don't actually ...


1

Make link like this <a href="http://example.com/?reaction=smk_remove_post&id=1226&_nonce=7be82cd4a0" data-id="1226" data-nonce="7be82cd4a0" class="smk-remove-post">Remove post</a> And jQuery $('.smk-remove-post').on( 'click', function( event ){ event.preventDefault(); var _this = $(this); var data = { 'action': ...


1

AJAX is not magical and when you request url X you will receive the same HTML for that url if you do it from the browser address bar, link or ajax. Therefor, if you want different response then the HTML you can not use the same url for the ajax request as in the link. Wordpress has a special "end point" to handle ajax request - admin-ajax.php and all ajax ...


1

Your problem is probably because you do not return a json object but an html (actually mixed text and html), and you set jQuery to validate that the response is json, which it isn't. your code at the ajax handler should be something like $catshtml = wp_dropdown_categories(.....echo=0); $ret = array('data' => $catshtml); wp_send_json($ret); die(); on ...


1

Don't even start. Ignoring official API is a no go, at best it will just creat headache for you and nasty surprise for the users when the plugin will fail when pinterest changes something and since it forces you to..... store user and password in a very unsecure way. This might be ok if your pugin is aimed to be run only for admins of non network wordpress ...


1

"How can I prevent unexpected output from reaching the browser/interfering with my AJAX response?" The Problem Something in your installation is generating "unexpected output," that is, it's creating content or data which should not be there if WordPress is running smoothly. This could imply a misconfigured server environment, a faulty WordPress ...


1

There is a way out, use complete instead of success or done posts = $.ajax({ type: 'GET', url: ajaxurl, async: false, dataType: 'json', data: { action : 'getHotelsList' }, complete: function(results) { and try to remove async:false if problem persists



Only top voted, non community-wiki answers of a minimum length are eligible