Я пытаюсь GET AJAX от моего контроллера, чтобы заполнить свой Datatable. Я тестировал свой GET с POSTMAN, и он обеспечивает правильный AJAX, а успех: функция работает правильно в моем DataTable.Datatable застрял на «обработке» при начальной загрузке
Однако, когда я загружаю свою страницу, DataTable застревает в «Обработка». Я пробовал переделывать обработку и обслуживать, и он по-прежнему не работает.
Когда я включаю ServerSide: Правду это recieves ошибки:
jquery-1.10.2.js:8720
GET http://localhost:51326/Table/Index?draw=1&columns%5B0%5D%5Bdata%5D=0&column…art=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1480635427759 404 (Not Found)
Вот мой контроллер, который предоставляет данные, а также мой класс, используемые для создания AJAX.
public class stockAJAX
{
public int StockId { get; set; }
public string ProductGroup { get; set; }
public string GroupType { get; set; }
public string ItemType { get; set; }
public string Model { get; set; }
public string SerialNo { get; set; }
public string NR { get; set; }
public string Status { get; set; }
public string Description { get; set; }
public string DateArrived { get; set; }
public int? CurrentLocation { get; set; }
public string TerminalId { get; set; }
}
public class TableController : Controller
{
List<stockAJAX> stock = new List<stockAJAX>();
stockAJAX ajaxTemp = new stockAJAX();
static string csv;
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public JsonResult getAJAX()
{
using (TableEntities context = new TableEntities())
{
stock = (from c in context.stocks
select new stockAJAX
{
StockId = c.StockId,
ProductGroup = c.ProductGroup,
GroupType = c.GroupType,
ItemType = c.ItemType,
Model = c.Model,
SerialNo = c.SerialNo,
NR = c.NR,
Status = c.Status.ToString(),
Description = c.Description,
DateArrived = c.DateArrived.ToString(),
CurrentLocation = c.CurrentLocation,
TerminalId = c.TerminalId,
}
).Take(1000).ToList();
}
return Json(stock, JsonRequestBehavior.AllowGet);
}
и вот мой Javascript, на мой взгляд, который относится к DataTable:
var Json = [
{StockId: 0,
ProductGroup: " ",
GroupType: " ",
ItemType: " " ,
Model: " " ,
SerialNo: " ",
NR: " " ,
Status: " ",
Description: " ",
DateArrived: " " ,
CurrentLocation: 0,
TerminalId: " ",
},
];
$("#myTable").DataTable({
"serverSide": true,
"processing": true,
"JQueryUI": true,
"stateSave": true,
"ajax": $.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'GET',
url: '/Table/getAJAX',
data: Json,
failure: function() {alert("unavailable AJAX");},
})
});
$('#loading').hide();
$('#myTable').show();
$("#myTable").DataTable().columns().every(function() {
var that = this;
$('input', this.footer()).on('keyup change', function() {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
});
и мой Datatable здесь:
<table class="table-fill" id="myTable">
<thead>
<tr>
<th>
<p1>Stock Id</p1>
</th>
<th>
<p1>Product Group</p1>
</th>
<th>
<p1>Group Type</p1>
</th>
<th>
<p1>Item Type</p1>
</th>
<th>
<p1>Model</p1>
</th>
<th>
<p1>Serial No</p1>
</th>
<th>
<p1>NR</p1>
</th>
<th>
<p1>Status</p1>
</th>
<th>
<p1>Description</p1>
</th>
<th>
<p1>Date Arrived</p1>
</th>
<th>
<p1>Current Location</p1>
</th>
<th>
<p1>Terminal ID</p1>
</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Product</th>
<th>Group</th>
<th>Item</th>
<th>Model</th>
<th>Serial</th>
<th>NR</th>
<th>Status</th>
<th>Descr</th>
<th>Date</th>
<th>Location</th>
<th>T-ID</th>
</tr>
</tfoot>
</table>
EDIT:
Вот мой индекс в контроллере:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Index(System.Web.Mvc.FormCollection collection)
{
//DateTime lastMonth = DateTime.Today.AddMonths(-6);
//Recieve Data from the Select Company DropDownList
string selectedList = collection["list"];
//Recieve Data from the Select GroupType DropDownList
string selectedGroupType = collection["grouptype"];
//Recieve Data from the Show All Stock checkbox
string selectedAmount = collection["amount"];
//A list of type <stock> has its value recieved from the function which computes which query to use and then executes it.
returnList(selectedGroupType, selectedList, selectedAmount);
//Returns the view
return View();
}
Ваш запрос '/ Table/Index', но ваш метод' getAJAX', * not * 'Index'. – Rob
@Rob Как мне сделать мой запрос getAJAX? Поскольку getAJAX - это функция, которая вернет JSON. Индекс строит мой взгляд. –
Извините, я немного неправильно понял. В этом случае у вас нет метода 'View' в вашем контроллере, который вам нужно будет создать – Rob