Javascript xmlHttpRequest.send(参数)在tomcat 7中不工作
我试图通过JS文件中编写的xmlHttpRequest.send(params)将一些参数发送到我的servlet,在那里我试图通过req.getParameter(“some_参数”)获取参数;它在servlet上返回null。不过,如果我通过在url中添加参数来发送参数,效果会很好。但是当url很大时,它会破坏代码。所以请有人帮帮我 提前谢谢Javascript xmlHttpRequest.send(参数)在tomcat 7中不工作,javascript,Javascript,我试图通过JS文件中编写的xmlHttpRequest.send(params)将一些参数发送到我的servlet,在那里我试图通过req.getParameter(“some_参数”)获取参数;它在servlet上返回null。不过,如果我通过在url中添加参数来发送参数,效果会很好。但是当url很大时,它会破坏代码。所以请有人帮帮我 提前谢谢 function doHttpPost(theFormName, completeActivity) { var xmlhttp = ne
function doHttpPost(theFormName, completeActivity)
{
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
var xmlMessage = buildPOST(theFormName, completeActivity);
var responseTxt;
try {
xmlhttp.Open(document.forms[theFormName].method, document.forms[theFormName].action+'?'+xmlMessage, false);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
responseTxt = xmlhttp.responseText;
}
}
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
enableDisableLinks(true);
setPointer();
xmlhttp.Send();
if(xmlhttp.Status != 200) {
alert("Post to server failed");
}
} catch (e) {
responseTxt = "Exception while posting form data: Error No: " + e.number + ", Message: " + e.description;
}
resetPointer();
enableDisableLinks(false);
var expectedTxt = "Form Data had been successfully posted to the database."
if(responseTxt.toString() == expectedTxt.toString()) {
// MNP: New requirement from Jeanne, should not refresh CM page, commenting it off for now
//if(completeActivity) {
// if (typeof (ViewCaseDetailBtn) != 'undefined') {
// ViewCaseDetailBtn.click();
// }
//}
return true;
} else {
alert (responseTxt);
}
return false;
}
错误
//IE only - shooting yourself in the
// Not all IE versions use ActiveX!
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); foot.
//JavaScript case sensitive, open !== Open
xmlhttp.Open(document.fo...
//JavaScript case sensitive, send !== Send
xmlhttp.Send();
//JavaScript case sensitive, status !== Status
xmlhttp.Status
如果您使用的是synchronous,它不会调用onreadystatechange
如果您使用的是POST,则该值需要位于send(“valuestosendup”)
中,而不是查询字符串上
这段代码说明了为什么您应该真正使用一个框架来进行Ajax调用,而不是使用自己的框架 您需要将它传递到
xmlhttp.Send(),而不是将xmlMessage
附加到URL的末尾
,比如xmlhttp.Send(xmlMessage)代码>这正是我尝试过的,但不起作用。上面我发布的代码运行良好。当我试图将其传递给xmlhttp.send(xmlMessage)时;它不起作用。奇怪的是,他们说它“起作用”,它只是不会发送值,除非他们将它们附加到URL。所以我想知道为什么这些语法错误没有发生你使用的旧IE浏览器是什么?问题是,如果你要发布,你需要做的是发送(),不,你在代码中的什么地方显示它。这不是我的问题。我指出,这是奇怪的,OP说它仍然有效,即使有语法错误,如.Send
和.Status
@Ian,哈哈,我甚至没有看名字。我觉得这很奇怪OP说它起作用了。