[英]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.