2013-03-14 50 views
0

我正在尋找天,以解決我的問題。 當我發送WP_Ajax_Response時,客戶端沒有收到它。 我檢查了互聯網上所有可能的提示,但仍然無法正常工作。 有人能幫助我嗎?Wordpress發送WP_Ajax_Response時未收到響應

我註冊的javascript文件:

wp_register_script('test-ajax-js',get_template_directory_uri() . '/library/script/ajax.test.js', array('jquery', 'wp-ajax-response'), '1.0'); 
wp_enqueue_script('test-ajax-js'); 
wp_localize_script('test-ajax-js', 'ajaxtest', 
        array( 
         'Ajax_Url' => admin_url('admin-ajax.php'), 
         'deshopNonce' => wp_create_nonce('deshop-ajax-test-nonce') 
        ) 
      ); 

這是PHP代碼:

add_action('wp_ajax_shop_ajax_test', 'test_function'); 
add_action('wp_ajax_nopriv_shop_ajax_test', 'test_function'); 

function test_function() { 
check_ajax_referer('deshop-ajax-test-nonce'); 


$response = array('what'=>'validate_user_login', 
      'action'=>'validate_user_login_results', 
      'id'=>'1', 
      'data'=>'OK' 
      ); 

$xmlResponse = new WP_Ajax_Response($response); 
$xmlResponse->send(); 

exit(); 
} 

,這是JavaScript文件:

jQuery(document).ready(function(event) { 
var post = { 
       action: 'shop_ajax_test', 
       _ajax_nonce: ajaxtest.deshopNonce 
      }; 

jQuery.post(ajaxtest.Ajax_Url, post, function(response){ 
       var res = wpAjax.parseAjaxResponse(response, 'ajax-response'); 
       jQuery.each(res.responses, function() { 
        var a = 0; 
       }); 
      }); 

}); 

在調試資源內容顯示響應= [0]。在jQuery.each函數中沒有處理任何響應!

非常感謝任何提示,可能會幫助我在這裏!

馬克

回答

0

我得到了同樣的問題,但我使用jQuery.ajax()沒有發佈解決它() 這裏有可能

0

是它在所有可能的域名,子域名的鏈接,或協議是不同的?這將導致瀏覽器不會發送Ajax響應。

此外,您是否使用過Firefox的螢火蟲或Chrome瀏覽器,顯然他們會向您顯示請求和響應(或者爲什麼它沒有到達那裏)?