<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="addType()" /> <script type="text/javascript" >
function addType() {
var getType = prompt("Please input Type", '');
if (getType!=null) {
var XmlHttp = createXMLHttpResponse();
if (XmlHttp) {
XmlHttp.onreadystatechange = interactWithServer(XmlHttp);
XmlHttp.open("GET", " interactWithAJAX.aspx?action=addType&type=" + getType,true);
XmlHttp.send();
}
else {
alert("XMLHttpResponse is null");
}
}
else {
alert("Type not be save");
}
}
function createXMLHttpResponse (){
if(window.ActiveXObject )
return new ActiveXObject("Microsoft.XMLHTTP");
else(window.XMLHttpRequest)
return new XMLHttpRequest();
} function interactWithServer(XmlHttp) {
if (XmlHttp.readyState == 4) {
if (XmlHttp.status == 200) {
var isAddToDB = XMLHttpRequest.responseText;
alert(isAddToDB);
}
else
{
alert("There are some problem on server ,and it's status is 400");
}
}
} </script>1我第一次写ajax,但是它不去调用asp.net的后台c#代码。请大家帮帮忙,看看为什么interactWithServer(XmlHttp)不去调用后台代码呢?2 我有些不理解 :
XmlHttp.onreadystatechange = interactWithServer(XmlHttp); //1
XmlHttp.open("GET", " interactWithAJAX.aspx?action=addType&type=" + getType,true); //2
XmlHttp.send();//3
1 不是已经连接上了服务器了吗?为什么2 open 和3 send 还在后面呢?求解AjaxJavaScript
解决方案 »
- 京东上边的横向的导航条怎么写的?
- 只能调用页内的js函数,调用不到外部的js文件里的函数
- 请教
- 请各位网友解释语句的作用(标号为1.2.3.4)
- 如何隐藏html页面菜单及地址栏??
- [原创]:2004末的彩蛋,FlashVml1.0(在线图像、动画、3D网页设计工具)发布
- if(!(isNaN(document.form1.user_age.value))有错!
- object一问 急
- css兼容性问题
- 如何实现多个div下li标签,一次点击显示6个,显示完标签之后替换图标,然后点击把li标签收只剩下4个,然后又换回原来的图标,各个div不冲突
- 用Jquery实现这题。
- 是jquery平常用的多还是js?
2、if (XmlHttp.status == 200) {
var isAddToDB = XmlHttp.responseText;
alert(isAddToDB);
}
3、 interactWithAJAX.aspx?这个路径 前有个空格 不知你本地是否有
可以参考一下
使用 SydAjax.ajax({url:'',type:'',success:function(data){}});
这行代码有问题,返回值永远为0,
注意URL是否需要加\
XmlHttp.onreadystatechange =function(){ interactWithServer(XmlHttp);};就好了