[英]Parameter not getting passed in AJAX call
我正在使用以下代碼
function test()
{
GetAttributesForSelectedControlType('Phone Number');
}
function GetAttributesForSelectedControlType(questionType) {
alert(questionType);
$.ajax({
url: '/Wizards/GetAttributesForSelectedControlType/' + questionType,
type: "GET",
contentType: "application/json",
success: function (result) {
alert('success');
}
});
}
請注意:QUESTIONTYPE是STRING值,而不是任何類型。
問題是在控制器中,我遇到了"GetAttributesForSelectedControlType"
函數,但參數值"GetAttributesForSelectedControlType"
空。 我在questionType
發送字符串。 有什么想法嗎?
function GetAttributesForSelectedControlType(questionType) {
alert(questionType);
$.ajax({
url: '/Wizards/GetAttributesForSelectedControlType',
contentType: "application/json",
data: {
questionType: questionType
},
success: function (result) {
alert('success');
}
});
}
如果您希望將問題類型作為參數傳遞,則應使用data:{qType:questionType}
它將填充函數GetAttributesForSelectedControlType
的參數qType。
嘗試:
function GetAttributesForSelectedControlType(questionType) {
$.get('/Wizards/GetAttributesForSelectedControlType', {questionType: questionType })
.done(function(data) {
alert('success');
});
}
您需要將questionType
作為數據傳遞。 或者,您可以只將以下內容添加到現有的ajax調用中。
data: {questionType: questionType }
這將通過以下操作起作用:
public ActionResult GetAttributesForSelectedControlType(string questionType)
{
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.