Jquery Ajax失败了 [英] Jquery Ajax is failing
问题描述
我正在使用Jquery Ajax在asp.net中调用我的pagemethod。当我使用
Hi,
I am using Jquery Ajax to call my pagemethod in asp.net. When I use
contentType: "application/json; charset=utf-8",
dataType: "json",
jquery ajax给了我错误,如果我不写内容类型和datatye然后补充页面html显示在respose中。下面是我的jquery ajax和.cs代码:
函数CallAjax()
{
>
$ .ajax({
类型:POST,
url:MyAdmin.aspx / GetLabelValue,
数据:{},
contentType:application / json; charset = utf-8,
dataType:json,
成功:功能(msg){
alert(''hi'');
},
错误:function(msg){提醒(''失败'')}
});
}
和MyAdmin.aspx.cs:
jquery ajax gives me error and if I dont write content type and datatye then comple page html is shown in the respose. below is my jquery ajax and .cs code:
function CallAjax()
{
$.ajax({
type: "POST",
url: "MyAdmin.aspx/GetLabelValue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(''hi'');
},
error: function(msg) { alert(''fail'')}
});
}
and MyAdmin.aspx.cs :
[WebMethod]
public static string GetLabelValue()
{
return "hello";
}
请指导我。谢谢!
问候,
Divya
Please guide me. Thanks !
Regards,
Divya
推荐答案
.ajax({
类型:POST,
url:MyAdmin.aspx / GetLabelValue,
数据: {},
contentType:application / json; charset = utf-8,
dataType:json,
成功:function(msg){
alert(''hi'');
},
错误:function(msg){alert( ''失败'')}
});
}
和MyAdmin.aspx.cs:
.ajax({
type: "POST",
url: "MyAdmin.aspx/GetLabelValue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(''hi'');
},
error: function(msg) { alert(''fail'')}
});
}
and MyAdmin.aspx.cs :
[WebMethod]
public static string GetLabelValue()
{
return "hello";
}
请指导我。谢谢!
问候,
Divya
Please guide me. Thanks !
Regards,
Divya
这里好'我在我自己的一个页面上使用的AJAX的语法,对我来说很好用:
Well here''s the syntax of the AJAX I''m using on one of my own pages, which works fine for me:
var xml;
var fetchError = false;
.ajax (
{
类型: GET,
contentType: json,
async: false ,
数据:{someVar:' 某些值'},
url: WebService.asmx / putStockplanFile,
成功: function (msg){
// 请求返回的商店消息
xml = msg;
},
错误: function (msg){
// 设置一个标志以指示r equest返回错误
fetchError = true ;
}
});
.ajax( { type: "GET", contentType: "json", async: false, data: { someVar: 'some value' }, url: "WebService.asmx/putStockplanFile", success: function (msg) { // store message returned by the request xml = msg; }, error: function (msg) { // set a flag to indicate request returned an error fetchError = true; } });
那么为什么不首先考虑它是否有任何区别。
So why not give that a go first to see if it makes any difference.
这篇关于Jquery Ajax失败了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!