asp.net ajax 无法使用,使用asp.net的jQuery ajax无法正常工作

我将拔出所有剩余的头发,因此,如果您知道可能是什么问题,请帮助我。谢谢。我所有的谷歌搜索和搜索都没有得到回报。

我正在尝试使用jquery进行ajax调用,但始终收到语法错误/解析错误消息。我尝试了许多不同的方法,但是当我将dataType设置为json时,它们都会导致错误。

这是我所拥有的:

$.ajax({

type: "POST",

url: "UserList.aspx/GetTestJson",

data: {}, //have also tried "{}" and other options such as removing the line

contentType: "application/json;charset=utf-8",

dataType: "json",

success: function(data, textStatus, jqXHR){

alert('success');

},

//Using below instead of above makes no difference either

//success: function(data){

// alert('success');

//},

error: function(jqXHR, textStatus, errorThrown){

alert('errorThrown: ' + errorThrown);

}

});

和aspx页面方法:

[WebMethod]

public static string GetTestJson()

{

return "Hello My World";

}

我也尝试过设置Web服务,但得到的结果相同。似乎返回的响应是该页面的完整html或来自Web服务的xml,并且由于我将dataType设置为json,因此无法成功解析。如果是这种情况,

如何将响应设置为仅返回json?

这是我尝试过没有运气的其他事情:

[WebMethod]

public static string GetTestJson()

{

HttpContext.Current.Response.ContentType = "application/json";

string json = JavaScriptConvert.SerializeObject("Hello My World");

return json;

}

我通过jQuery得到的错误消息:

errorThrown.message = "Syntax error"

errorThrown.number = -2146827286

errorThrown.name = "SyntaxError"

textStatus = "parseerror"

jqXHR.status = 200

jqXHR.statusText = "OK"

jqXHR.readyState = 4

jqXHR.responseText = (the complete html of the page)

有什么想法或建议吗?

谢谢

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值