值得注意的
當傳入是Json類型的時候要var user = eval(result.d);
當傳入是字符串的時候要用eval("exception = "+result.responseText);
復制代碼 代碼如下:
$.ajax
(
{
type: "POST",
contentType: "application/json",
url: serviceURL+"/UserLogin",
data: "{UserLoginID:'"+$('#txtLoginID').val()+"',UserLoginPW:'"+$('#txtLoginPW').val()+"'}",
dataType: 'json',
success: function(result)
{
var user = eval(result.d);
//eval("user="+result.d);
location.href = "Welcome.aspx?userID="+user.UserID
},
error: function(result, status)
{
if(status == 'timeout')
{
alert("The request timed out, please resubmit");
}
else
{
eval("exception = "+result.responseText);
//var exception = eval(result.responseText);
alert(exception.Message);
}
}
}
);