今天在写$.ajax调用.net的ashx文件时,发现ajax异步请始终不能进入到ashx文件中,搞了半天,发现是因为ashx文件是从其他项目中copy过来,再修改了它的命名空间导致的问题,原来修改了.ashx.cs文件的命名空间后,还有一个.ashx的文件中也存在命名空间,也要修改过来,但此文件在VS中是不能打开的,所以一直找原因,现在解决了,记录一下,以免自己下次犯同样的错误。
1、页面中的脚本内容:
$.ajax({
cache: false ,
async: false ,
type: " POST " ,
data: {},
url: " /AppCode/Ajax.ashx " ,
success: function (response) {
// do something
},
error: function (msg) {
alert( msg.responseText ); //输出了出错的信息
}
});
cache: false ,
async: false ,
type: " POST " ,
data: {},
url: " /AppCode/Ajax.ashx " ,
success: function (response) {
// do something
},
error: function (msg) {
alert( msg.responseText ); //输出了出错的信息
}
});
2、.ashx文件中的代码:(其中:Wesley.Test.UI.Ajax 是命名空间)
<%
@ WebHandler Language
=
"
C#
"
CodeBehind
=
"
Ajax.ashx.cs
"
Class
=
"
Wesley.Test.UI.Ajax
"
%>