[英]Ajax call inside @onchange throws error “url undefined”
我試圖在用戶更改父下拉菜單時調用Ajax來填充下拉菜單,但是我收到url undefined錯誤,請問有人可以指導我嗎
提前致謝。
.cshtml:
@Html.DropDownList("queueclientDropdownList", new SelectList(Model.Clients, "Id", "Name"), "Select Client", new { ng_model = "queueclientDropdownList", ng_required = "false", ng_value = "false", @class = "form-control", @onchange = "ClientChange()" })
Ajax電話:
function ClientChange() {
var clientId = $('#queueclientDropdownList').val();
$.ajax({
url: '/QueueBuilder/GetDepartmentsByClient',
type: "POST",
dataType: "JSON",
data: { clientId: clientId },
success: function (data) {
$("#queuedepartmentDropdownList").empty();
$("#queuedepartmentDropdownList").append($('<option></option>').val(0).html("Select Department"));
$.each(data, function (i, department) {
$("#queuedepartmentDropdownList").append($('<option></option>').val(department.Id).html(department.Name));
});
}
});
return true;
}
請嘗試將您的url參數更改為:
url: 'your_project_baseurl/controller/method/function_name',
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.