2015-04-02 70 views
0

我真的不知道爲什麼,但函數(響應) - 部分根本不會被執行 - 儘管我的控制器中的獲取方法被getJSON調用。

腳本:

$.getJSON(getUrl, { 
     BUID: buID, 
     AID: aID, 
     LID: lID 
    }, function (response) { 
     $('#Test').text("TEST"); 
    }) 
}; 

控制器:

public JsonResult GetMeasures(int buID) { 
     return Json(new { Success = true }); 
    } 

我跨度元素的文本不會被改變成 「TEST」。

+0

'這是$ ('#Test')。text(「TEST」);' – lshettyl 2015-04-02 09:11:01

+0

@lshetty感謝您的迴應 - 但即使使用$('#Test').text(「TEST」);它不工作。 – C4p741nZ 2015-04-02 09:13:38

+0

你真的需要解釋_it不工作_因爲我不知道什麼是_it_! – lshettyl 2015-04-02 09:15:14

回答

0

發送正確的參數:

$.getJSON(getUrl, { 
     buID: buID 
    }, function (response) { 
     $('#Test').text("TEST"); 
    }) 
}; 

然後你需要使用JsonRequestBehavior.AllowGet與JSON回報,還與HttpGet屬性裝飾你的功能

[HttpGet] 
public JsonResult GetMeasures(int buID) { 
     return Json(new { Success = true }, JsonRequestBehavior.AllowGet); 
} 

一個良好的閱讀Why is JsonRequestBehavior needed?