【发布时间】:2021-08-30 12:51:41
【问题描述】:
这是我的代码。单击“添加项目”按钮时调用函数 AddRow。调试后发现ajax调用没有执行,这是什么问题?
function AddRow() {
debugger;
$.ajax({
type: "POST",
dataSource: [@(JavascriptArray(Model.Categories.Select(x => new { CategoryId = x.CategoryId,Category=x.Category, Display = $"{x.Category}" }).OrderBy(x => x.Display)))],
dataType: "json",
contentType: "application/json",
success: function (res) {
debugger;
$.each(res.d, function (data, value) {
$("#category").append($("<option></option>").val(value.categoryId).html(value.category));
});
}
});
var row = "<tr>" +
"<td><input type='text' style='max-width: 300px' id='title' class='form-control' /></td>" +
"<td><select class='form-control' style='width: 120px;height:38px' id='category'><option value='0'></option></select></td>" +
//"<td><input type='text' style='max-width: 90px' name='category' id='category' class='form-control' placeholder='Category...' /></td>" +
"<td><input type='number' style='max-width: 75px' id='price' min=0 class='form-control' /></td>" +
"<td><input type='number' style='max-width: 75px' id='quantity' min=0 class='form-control' /></td>" +
"<td><input type='button' value='Add' onclick='addItem()' class='btn btn-success'/>  " +
"<input type='button' value='Cancel' onclick='deleteNewItem(this)'name='removeLines[0]' class='btn btn-danger' />" +
"</td>" +
"</tr>";
$('#CartTableBody').prepend($(row));
}
我已经使用提供数据的操作方法更新了 url,但仍然显示警告错误消息
$(document).ready(function () {
debugger;
$.ajax({
type: "Get",
url: "@Url.Action("GetCategory", "Release")",
dataType: "json",
contentType: "application/json",
success: function (res) {
debugger;
$.each(res.d, function (data, value) {
$("#category").append($("<option></option>").val(value.categoryId).html(value.category));
});
},
error: function (Result) {
alert("Error");
}
});
})
【问题讨论】:
-
开发者控制台有错误吗?尝试调试这个:
$.ajax({...}).done(function(response){}).fail(function(error){})
标签: javascript c# jquery asp.net-core