1、js代码
function callAjax(url, postParams) {
beforeInvoke();
createXMLHttpRequset();
xmlHttpRequest.open("post",url,true);
xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttpRequest.onreadystatechange=function() {
if(xmlHttpRequest.readyState == 4) {
finishInvoke();
if(xmlHttpRequest.status == 200) {
var returnValue = xmlHttpRequest.responseText;
backInvoke(returnValue);
}
}
};
xmlHttpRequest.send(postParams);
}
2、html:
function callAjax(url, postParams) {
beforeInvoke();
createXMLHttpRequset();
xmlHttpRequest.open("post",url,true);
xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttpRequest.onreadystatechange=function() {
if(xmlHttpRequest.readyState == 4) {
finishInvoke();
if(xmlHttpRequest.status == 200) {
var returnValue = xmlHttpRequest.responseText;
backInvoke(returnValue);
}
}
};
xmlHttpRequest.send(postParams);
}
2、html:
本文介绍了一种使用Ajax进行前后端数据交换的方法。通过一个具体的JavaScript函数示例,展示了如何发送POST请求,并设置请求头为application/x-www-form-urlencoded。此外,还介绍了如何根据服务器响应的状态码来判断请求是否成功,并对返回的数据进行处理。
1万+

被折叠的 条评论
为什么被折叠?



