私のコントローラからAJAXを取得しようとしています。私はPOSTMANで私のGETをテストし、それは正しいAJAXを提供し、成功:関数は私のDataTableで正しく動作します。初期ロード時に "処理中"でデータテーブルがスタックする
ただし、私のページを読み込むと、DataTableは「処理中」に固執します。私は処理をオフに変更しようとしていますし、それを有効にしても機能しません。
私はサーバサイドターン
:ここ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を作成するために使用されるデータだけでなく、私のクラスを提供し、私のコントローラがある:真のそれはエラーをrecieves。
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);
}
、ここのDataTableに関連する私の見解で私のjavascriptです:
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>
編集:ここでは
は私の指数でありますコントローラの機能:
[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'です。* 'Index'ではありません。 – Rob
@RobどうすればgetAJAXをリクエストできますか? getAJAXはJSONを返す関数です。インデックスは私のビューを構築します。 –
申し訳ありませんが、私はそれを少し誤解します。その場合、コントローラに 'View'メソッドがありません。これは、 – Rob