0

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);  
      jQuery.ajax({
                  type: 'POST',
                  url: script.axurl,
                  data: {"action": "wk_check_myshop","shop_slug":self.val(),"nonce":script.nonce},
                success: function(resp)
                { 
                  console.log(resp);
                  if ( response == 0){
                         console.log(response);
                    }  
                }
          });

  });

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() ));
3
  • The problem is in the function wk_check_myshop_value.
    – fuxia
    Oct 8 '16 at 12:36
  • Hello thanks for your answer i had already defined this function Oct 8 '16 at 13:01
  • And where is it? That's exactly the part that is missing in your question.
    – fuxia
    Oct 8 '16 at 14:57
-1

Your Ajax hooked function is:

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

Try changing die; to die();

1
  • Hallo thanks for your reply actually there was no bug in the code the bug was the class object Oct 8 '16 at 15:13
0

You can try to return à json response:

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

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, privacy policy and cookie policy

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