2013-03-14 89 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浏览器,显然他们会向您显示请求和响应(或者为什么它没有到达那里)?