2014-04-02 68 views
0

我正在使用MVC4控制器返回值到ajax函數來做一些事情在客戶端。不幸的是,返回值沒有綁定到ajax方法。請幫幫我。jquery ajax函數不綁定返回結果

我的ajax方法;

$.ajax({ 
     type: 'GET', 
     url: '/Service/Utility/GetcustomerAddressProofByCustomerId', 
     data: { customerId: customerId }, 
     success: function (rtnResult) { 
       if (rtnResult.Result.lenght > 0) { 
        alert("ok"); 
       } 
       else { 
        alert("no"); 
       } 
       } 
     }); 

控制器方法;

public ActionResult GetcustomerAddressProofByCustomerId(int customerId) 
     { 
      List<CustomerSecondaryID> items = db.CustomerSecondaryID.Where(a => a.customerId == customerId).ToList(); 

      return Json(items , JsonRequestBehavior.AllowGet); 
     } 

請幫我做到這一點。

+0

dataType:'json''在哪裏? – webdeveloper

+0

就像一個提示(我每天使用),你可以寫「console.log(rtnResult);」 +任何體面的瀏覽器,我會建議鉻,看看結果的格式,以協助您調試您的JavaScript。 –

+0

是的。它的JSON,但它也會提醒(「否」) – user2710638

回答

0

還有一個錯字lenght您也可以直接在rtnResult上調用length,因爲它是一個數組。當您返回時設置dataType:'json'application/json內容類型

success: function (rtnResult) { 
      if (rtnResult.length > 0) { 
      alert("ok"); 
      }, 
dataType:'json'