识别ajax-jquery中获取web方法的返回值

时间:2012-07-10 06:59:22

标签: c# jquery asp.net ajax

我写了一个带有字符串返回值的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);
            }
            }
       );

1 个答案:

答案 0 :(得分:4)

ret.lenght应在ret.d.length回调中success