JavaScript Eval 函数使用_javascript技巧
程序员文章站
2022-05-20 11:53:26
...
值得注意的
当传入是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);
}
}
}
);
当传入是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);
}
}
}
);
推荐阅读