Asp.net jquery ajax调用错误方法而不是success的响应
我正在调用jQueryAjax来访问一个页面,如下所示Asp.net jquery ajax调用错误方法而不是success的响应,asp.net,jquery,Asp.net,Jquery,我正在调用jQueryAjax来访问一个页面,如下所示 <script type="text/javascript"> function Showgrid() { $.ajax({ type: "GET", url: "popup.aspx", contentType: "application/json; charset=utf-8", data: {loca
<script type="text/javascript">
function Showgrid() {
$.ajax({
type: "GET",
url: "popup.aspx",
contentType: "application/json; charset=utf-8",
data: {locale: 'en-US' },
dataType: "json",
success: function (data) {
$("#target").html(data.d);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
}
</script>
我得到的是响应,但不是成功方法,而是错误函数
请说明错误所在更改为
POST
,即改为键入:“POST”
。在页面中转到Response.Write(请求[0])代码>您在.aspx页面上的输出不是json类型。在写入响应之前使用Json编码或更改数据类型:text如上所述,将type更改为POST并将数据括在引号中。在服务器端,需要调用web方法。传递参数“locale”时不能使用page_load。请参阅下面修订的JSON函数和服务器代码(假设您使用的服务器端代码正确):
JSON:
请改用Asp.net页面方法。谷歌就是这样。
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
Response.Write(Request.QueryString[0]);
Response.Write(DateTime.Now.ToString());
Response.End();
}
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static void ShowGrid(string locale)
{
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.Write(HttpContext.Current.Request.QueryString[0]);
HttpContext.Current.Response.Write(DateTime.Now.ToString());
HttpContext.Current.Response.End();
}
function Showgrid() {
$.ajax({
type: "POST",
url: "popup.aspx/ShowGrid",
contentType: "application/json; charset=utf-8",
data: "{ 'locale': 'en-US' }",
dataType: "text",
success: function (data) {
$("#target").html(data.d);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
}