【发布时间】:2010-04-23 15:18:14
【问题描述】:
我正在尝试使用 jQuery 将同步 AJAX 发布到服务器,并返回 JSON 响应。
我想在成功返回时设置一个 javascript 变量 msg
这是我的代码的样子:
$(document).ready(function(){
$('#test').click(function(){
alert('called!');
jQuery.ajax({
async: false,
type: 'POST',
url: 'http://www.example.com',
data: 'id1=1&id2=2,&id3=3',
dataType: 'json',
success: function(data){ msg = data.msg; },
error: function(xrq, status, et){alert('foobar\'d!');}
});
});
[编辑]
我在以前的 xode 中不小心混合了 PHP 和 Javascript(现已更正)。然而,我现在得到这个更神秘的错误信息:
未捕获的异常:[异常...“组件返回失败代码:0x80070057(NS_ERROR_ILLEGAL_VALUE)[nsIXMLHttpRequest.open]”nsresult:“0x80070057(NS_ERROR_ILLEGAL_VALUE)”位置:“JS框架::http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js::匿名::第 19 行”数据:无]
什么...?
【问题讨论】:
-
您的 PHP 脚本是否打印出有效的 JSON 格式文本?