jQuery.post()回调无法执行
问题描述:
我正在使用jQuery.post()
并且一切正常,只是没有调用回调函数。jQuery.post()回调无法执行
数据发送正常,服务器正常接收等,但事后没有任何反应。我试图复制参考代码无济于事。
这是我使用javascript内联:
<head>
<title></title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function submit_login_cb(data,status) {
alert(data);
}
function submit_login() {
$.post("http://localhost:8051/", $("#login_form").serialize(), function(data,status){submit_login_cb(data,status);}, "json");
}
</script>
</head>
为什么不工作的回调?
编辑:返回jqXHR
对象的statusText
字段只是说“错误”...虽然没有其他事情发生(POST请求注册在服务器上)。
编辑:Chrome开发者工具正在打印此控制台: XMLHttpRequest cannot load http://localhost:8051/. Origin null is not allowed by Access-Control-Allow-Origin.
答
对不起忘了更新此,要解决这个问题,只允许空产地的WSGI服务器上。
你得到任何javascript错误? – kleinohad 2012-07-21 06:15:47
@kleinohad不,它只是默默地失败。 – Joshua 2012-07-21 06:17:28
服务器是否正确响应?您是否尝试向返回的['jqXHR'](http://api.jquery.com/jQuery.ajax/#jqXHR)添加错误处理程序? – 2012-07-21 06:22:06