I am using ajax in wordpress , i have done every thing right please update me why i ajax returning zero even if code is correct is there something else in the page which is forcing ajax to return 0. her eis my code for js

 jQuery('#seller-shop').on('focusout', function() {  
      var self = jQuery(this);  
                  type: 'POST',
                  url: script.axurl,
                  data: {"action": "wk_check_myshop","shop_slug":self.val(),"nonce":script.nonce},
                success: function(resp)
                  if ( response == 0){


code for php is

add_action( 'wp_ajax_nopriv_wk_check_myshop',array($mp_obj,'wk_check_myshop_value') );

add_action( 'wp_ajax_wk_check_myshop',array($mp_obj,'wk_check_myshop_value'));

Thsi code is inside wp enqueue script hook

wp_localize_script( 'marketplace', 'script', array( 'axurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('ajaxnonce'), 'seller_page' => $page_name , 'site_url' =>site_url() ));
  • The problem is in the function wk_check_myshop_value.
    – fuxia
    Commented Oct 8, 2016 at 12:36
  • Hello thanks for your answer i had already defined this function Commented Oct 8, 2016 at 13:01
  • And where is it? That's exactly the part that is missing in your question.
    – fuxia
    Commented Oct 8, 2016 at 14:57

2 Answers 2


Your Ajax hooked function is:

function wk_check_myshop_value() { echo "asdasd";  die;}

Try changing die; to die();

  • Hallo thanks for your reply actually there was no bug in the code the bug was the class object Commented Oct 8, 2016 at 15:13

You can try to return à json response:

echo json_encode(array('message'=> 'the message'));

Then in the js script you need to parse the json response with var json = $.parseJSON(response);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.