跪求高手解答一下关于Ajax的一个问题。 - Web 开发 / Ajax
通过Button的onclick="DoAjax('Ajax.aspx', CallBack)"调用时,总是提示缺少对象?怎么回事儿?
再有就是Javascript怎么向服务器提交xml格式文件呢?我用XMLHttpRequest.send(xml);发送时,好像用为xml
包含了特殊符号<,/,>无法发送一样,应该怎样处理呢?JavaScript用没用想asp.net中htmlEncode编码方法啊?
<script type="text/javascript">
var xHRequest;
function CreateXHR(){
if (window.ActiveXObject){
xHRequest = new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
else if (window.XMLHttpRequest){
xHRequest = new XMLHttpRequest();
}
else alert("Your browser don't support XmlHttpRequest!");
}
function DoAjax(RequestURL, Fun){
CreateXHR();
if (xHRequest){
xHRequest.onreadystatechange = Fun;
xHRequest.open("post", RequestURL, true);
xHRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
// xHRequest.send("<fjdaslfj>");
xHRequest.send(CreateXML());//为什么这里总是Microsoft JScript 运行时错误: 缺少对象呢?
}
}
function CallBack(){
if (xHRequest.readyState == 4){
if (xHRequest.status == 200){
var a = xHRequest.responseText;
document.getElementById("myDiv").innerHTML = xHRequest.responseText;
}
}
}
function CrateXML(){
var xml = "<?xml version='1.0' encoding='gb2312'?> <pets>";
xml = xml+"<name>"+name+"</name><pwd>"+pwd+"</pwd>";
xml= xml+"</pets>";
return xml;
return "dasjfljasdf";
}
</script>
------解决方案--------------------是
function CreateXML()
不是
function CrateXML()
------解决方案--------------------另外,name pwd也没有定义
------解决方案--------------------参考
ajax指定为post但是未设置content-type或未指定键时时如何获取提交的内容
并且Ajax.aspx给page指令加上 ValidateRequest="false" ,要不提交包含了html标签时会出错