【发布时间】:2011-09-27 20:38:54
【问题描述】:
这是我尝试的第一个简单的 javascript ajax 请求,但没有成功。
var obj = {};
obj.action = "clubbar";
$.post("/ajax/lojack", obj, function(data){
var real = JSON.parse(data);
});
当我执行 json 解析函数时,我得到了这个错误
uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://localhost:8888//admin/newclubbar.jsp :: <TOP_LEVEL> :: line 381" data: no]
当我尝试不使用 jquery 时,我得到了同样的错误:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data = JSON.parse(xmlhttp.responseText);
}
}
xmlhttp.open("GET","/ajax/lojack?action=clubbar",true);
xmlhttp.setRequestHeader("Content-type", "text/html");
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(null); I also tried xml.http.send("");
我可以发布实际的 JSON,但 Webkit 没有问题
【问题讨论】:
-
感谢编辑,由于某种原因,这条评论没有打到我的收件箱。它是一个 j2ee 应用程序,因此在我删除所有 Java 包含并仅使用 html/css/javascript 离开页面后,异常从第 381 行更改为第 370 行。这是第 368 - 372 行:
-
var a = document.createElement('a'); a.setAttribute('href', ''); a.setAttribute('going_' + nbhood.id); a.setAttribute('data-role', 'button');a.innerHTML = "Going"; -
最诚挚的歉意.....
a.setAttribute('going_' + nbhood.id);你说对了行号 setAttribute 有两个参数...duhhhhhhh。我累了。
标签: ajax json firefox xmlhttprequest