Always a zero after an ajax response
-
Hello there :]
I’m trying to create a ajaxrequest in a plugin using jQuery and
admin-ajax.php
. But the response of this request always ends with a zero. I’m not sure it’s an error or a bug or so, but this is not how it should be anyway :]This is a part of the code:
function secretnameofmyawesomeplugin_js(){ if(isset($_POST['url']) && !empty($_POST['url'])){ echo 'ok'; } else { echo 'false'; } }
…
// At this point the Javascript was loaded add_action('admin_menu', 'init'); // The connection between admin-ajax and my php ajax function add_action('wp_ajax_secretnameofmyawesomeplugin_js', 'secretnameofmyawesomeplugin_js', 10);
This is a piece of the Javascript code (obviously I’m using PHP also):
$.post('<?php echo $site_url;?>/wp-admin/admin-ajax.php', { 'action': 'secretnameofmyawesomeplugin_js', 'cookie': encodeURIComponent(document.cookie), 'url': url }, function(str){ if(str == 'ok'){ alert('Ok!'); } else { alert('Noooeess, something went wrong: ' + str); } } );
The response is
ok0
instead ofok
at the moment. Does anyone know a solution to get rid of the0
at the end?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Always a zero after an ajax response’ is closed to new replies.