我写了一个带有字符串返回值的web方法。这个返回值得到表单存储过程。但是当条件没有建立时,未定义的值返回.i写了下面的代码,但它没有用
$.ajax(
{
type: "POST",
url: "WebForm1.aspx/confirm",
data: JSON.stringify({
username: username,
password: password, email: email,codemeli: codemeli}),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (ret) {
if (ret != "") {
$('#result').text(ret.d + " : " + "it is reserved "+ret.lenght); }
else { $('#result').text("the operation is successful"); }
},
error: function (x, e) {
$('#result').text(x.responseText);
}
}
);
答案 0 :(得分:4)
ret.lenght
应在ret.d.length
回调中success
。