Datatables.net AJAX不工作 - 为什么? [英] Datatables.net AJAX is not working - why?

查看:84
本文介绍了Datatables.net AJAX不工作 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我评论的代码不起作用。它失败了:函数....为什么?

我最终使用loadData()函数来完成任务。



有人可以告诉它有什么问题(非工作代码)吗?



如果您需要更多代码我可以发布更多代码...



谢谢。

-------

The code I commented is not working. It failed on error: function.... why?
I ended up to use loadData() the work around function to do the task.

Can someone please tell what is wrong with it (the non working code)?

I can publish more code if you need more...

Thanks.
-------

    <script type="text/javascript">
        $(document).ready(function () {
            loadData();
        });
// What is wrong with the code?
        //$(document).ready(function () {
            //var refDataTable = $("#example").dataTable({
            //    processing: true,
            //    serverSide: true,
            //    ajax: {                   
            //        data: '{}',
            //        type: "POST",
            //        url: "BolAddress.aspx/GetAddress",
            //        contentType: "application/json; charset=utf-8",
            //        dataType: "json",
            //        success: function (response) {
            //            alert(response.d);                      
            //        },
            //        failure: function (response) {
            //            alert(response.d);
            //        },
            //        error: function (response) {
            //            alert(response.d);
            //        }
            //    },
            //    columns: [
            //        { data: "CardId" },
            //        { data: "CardType" },
            //        { data: "Company" },
            //        { data: "Address" },
            //        { data: "City" },
            //        { data: "State" },
            //        { data: "Zip" },
            //        { data: "Phone" },
            //        { data: "Contact" },
            //        { data: "Description" }
            //    ]
            //})
        //});
// ------------------------------------------
        function loadData() {
            $.ajax({
                type: "POST",
                url: "BolAddress.aspx/GetAddress",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    OnSuccess(response);
                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        };
        function OnSuccess(response) {
            var cards = response.d;
            var cardtable = $("#example");
            $(cards).each(function () {
                var row = $("<tr />");
                cardtable.append(row);
                row.append($("<td>" + this.CardId + "</td>"));
                row.append($("<td>" + this.CardType + "</td>"));
                row.append($("<td>" + this.Company + "</td>"));
                row.append($("<td>" + this.Address + "</d>"));
                row.append($("<td>" + this.City + "</td>"));
                row.append($("<td>" + this.State + "</td>"));
                row.append($("<td>" + this.Zip + "</td>"));
                row.append($("<td>" + this.Phone + "</td>"));
                row.append($("<td>" + this.Contact + "</td>"));
                row.append($("<td>" + this.Description + "</td>"));
            });
            var refDataTable = $("#example").dataTable();
        }
    </script>





我尝试了什么: < br $> b $ b

无论如何都无法正常工作。它在'error:'上失败并提醒我response.d。



What I have tried:

It is not working no matter what. It failed on 'error:' and alert me response.d.

推荐答案

(document).ready(function(){
loadData();
});
//代码有什么问题?
//
(document).ready(function () { loadData(); }); // What is wrong with the code? //


(document).ready(function(){
// var refDataTable =
(document).ready(function () { //var refDataTable =


(#示例)。dataTable({
//处理:true,
// serverSide:true,
// ajax:{
//数据:'{}',
//类型:POST,
// url:BolAddress.aspx / GetAddress,
// contentType:application / json; charset = utf-8,
// dataType:json,
//成功:函数(响应){
// alert(response.d);
//},
//失败:function(response){
// alert(response.d);
//},
//错误:函数(响应){
// alert(响应。 d);
//}
//},
//列:[
// {data:CardId},
// {data:CardType},
// {data:Company},
// {data:Address},
// {data:City},
// {data:State},
// {data:Zip},
// {data:Phone},
// {data:Contact},
// {data :Description}
//]
//})
//});
// ------------------------------------------
function loadData(){
("#example").dataTable({ // processing: true, // serverSide: true, // ajax: { // data: '{}', // type: "POST", // url: "BolAddress.aspx/GetAddress", // contentType: "application/json; charset=utf-8", // dataType: "json", // success: function (response) { // alert(response.d); // }, // failure: function (response) { // alert(response.d); // }, // error: function (response) { // alert(response.d); // } // }, // columns: [ // { data: "CardId" }, // { data: "CardType" }, // { data: "Company" }, // { data: "Address" }, // { data: "City" }, // { data: "State" }, // { data: "Zip" }, // { data: "Phone" }, // { data: "Contact" }, // { data: "Description" } // ] //}) //}); // ------------------------------------------ function loadData() {


这篇关于Datatables.net AJAX不工作 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆