ajax返回值一直报错Pasererror

sypwish 2017-05-17 08:13:16

$("#btn").click(function(){

var user = JSON.stringify({
uname:$("#form-username").val(),
pwd:$("#form-password").val() });

$.ajax({
type:"POST",
url:"http://localhost:53168/LoginService.asmx/HelloWorld2",
async:true,

contentType: "application/json;charset=utf-8",
data:user,
datatype:"text",
success:function(data){
// var obj = eval("("+data+")");
alert(1);
alert(data);
},
error:function(XMLHttpRequest, textStatus, errorThrown)
{

alert(textStatus);
}
});

});



[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public void HelloWorld2(string uname, string pwd)
{
HttpContext.Current.Response.ContentType= "application/json;charset=utf-8";
JavaScriptSerializer jss = new JavaScriptSerializer();
Test t = new Test();
t.name = uname;
t.pwd = pwd;

HttpContext.Current.Response.Write(jss.Serialize(t));

}

ajax返回值一直报错Pasererror

firebug下的post信息
头信息Post响应缓存
JSON


pwd
"1"

uname
"1"
源代码
{"uname":"1","pwd":"1"}

相应信息 {"name":"1","pwd":"1"}{"d":null}

急求
...全文
595 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2017-07-14
  • 打赏
  • 举报
回复
dataType:"text", 注意大小写,肯定是响应头是json,jquery自动用JSON.parse转了,而且你返回的数据有问题,不是标准json字符串所以提示这个错误
sypwish 2017-07-09
  • 打赏
  • 举报
回复
$.parseJSON(data.d);
陌生人的魅力 2017-06-27
  • 打赏
  • 举报
回复
alert(1); 不报错?

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧