我在 html 正文中有一个带有“按钮帐户”名称的 html 按钮,并且希望在用户单击按钮时使用 ajax 更新 aspx 页面
我在 google chrom 中收到此错误
SyntaxError: JSON.parse: 意外字符
这在火狐中
SyntaxError: JSON.parse: 意外字符
这是我的代码
<script type="text/javascript" >
$(document).ready(function () {
$("#button-account").bind("click", "accountRegister");
function accountRegister() {
var waitObj = "<span class='wait' > <img src='Resource/Images/loading.gif' alt='' /> </span>";
var user = $("[name='username']").val();
var pass = $("[name='password']").val();
var dataObj = {
"username": user,
"password": pass,
};
$.ajax({
type: "POST",
url: "Checkout.aspx/login",
data: dataObj,
contentType: "application/json; charset=utf-8",
dataType: "json",
beforSend: function () {
$(this).attr("disabled", "true");
$(this).after(waitObj);
},
success: function (msg) {
// Replace the div's content with the page method's return.
alert("success");
$("#checkout").slideUp("slow");
$("#payment-address").slideDown("slow");
},
error: function (msg) {
alert("error");
},
complete: function () {
$(this).attr("disabled", "false");
$(".wait").remove();
},
});
}
});
</script>
这是我的网络方法
[WebMethod]
public static string login()
{
//bool UserIsValid = false;
//string userName = "";
//string pass = "";
//MembershipUser u = Membership.GetUser(userName);
//pass = u.GetPassword();
//if (UserIsValid)
//{
// // returnAsHtml = "true";
//}
//else
//{
// //returnAsHtml = "use is not valid";
//}
JavaScriptSerializer js = new JavaScriptSerializer();
string result = js.Serialize("{ a:'1' }");
return result;
}
和提琴手返回 200 状态。 但返回 html。我知道这是我的错误。怎么解决?
任何帮助都是合适的...