<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 这是jquery的引用文件
$(document).ready(function () { $("#send").click(function () {
$.ajax(
{
url: "../JqueryAjax/JqueryAjaxServer.aspx",
type: 'post', dataType: 'json', timeout: 30000,
data: { "username": $("#username").val(), "content": $("#content").val() },//这边其实没有用到
success: function (data, textStatus)
{
alert("success");
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert("error");
alert(textStatus);
alert(errorThrown.toString());
}
}
);
}
);
});
服务端ASP.NET代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType ="application/json";
string a = "{\"username\":\"test\" ,\"content\":\"test\"}";
Response.Write(a);
}但是一直会出错,error函数会被调用到,提示invalid json,请大家帮忙看下。是
$(document).ready(function () { $("#send").click(function () {
$.ajax(
{
url: "../JqueryAjax/JqueryAjaxServer.aspx",
type: 'post', dataType: 'json', timeout: 30000,
data: { "username": $("#username").val(), "content": $("#content").val() },//这边其实没有用到
success: function (data, textStatus)
{
alert("success");
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert("error");
alert(textStatus);
alert(errorThrown.toString());
}
}
);
}
);
});
服务端ASP.NET代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType ="application/json";
string a = "{\"username\":\"test\" ,\"content\":\"test\"}";
Response.Write(a);
}但是一直会出错,error函数会被调用到,提示invalid json,请大家帮忙看下。是
你所谓的"这边其实没有用到"是什么意思?
注意特殊字符.
......
Response.Write(a);//Add
Response.End();