简体   繁体   English

如何通过Datatable使用Ajax请求发送发布数据

[英]How to send post data with ajax request though Datatable

I have been trying to send some post data with ajax request to server through datatables ,following is my code 我一直在尝试通过数据表向服务器发送一些带有ajax请求的发布数据,以下是我的代码

<script type="text/javascript">
    //this is the datatable it brings data in json format from server
    $(document).ready(function() {
        var selected = $("#mainschool_id option:selected").val();
        //alert(selected);
        $('#example').dataTable({
            "bProcessing": true,
            "ajax": {
                "url": "/nvs/system/modules/NVS.NLI/elements/trainingalldatatable.jsp",
                "data": {
                    data: selected
                }

            },
            "sAjaxSource": "/nvs/system/modules/NVS.NLI/elements/trainingalldatatable.jsp",
            "search": {
                "smart": false
            },
            "scrollX": true,
            "aoColumns": [{
                    type: "text"
                },
                {
                    type: "number"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                },
                {
                    type: "text"
                }]
        });
    });
</script>

But it is throwing ajax error ,every time i am using .There is no specific explaination for using datatables with jsp and java.Any help would be really appreciated .Thanks 但这每次我使用时都会抛出ajax错误。对于将数据表与jsp和java结合使用,没有具体的解释。非常感谢您的帮助。谢谢

As your are using two urls one from Sajaxsource and othe inside ajax ,you dont have to use ajaxsource in this case 由于您使用的是来自Sajaxsource的两个url和位于ajax内部的其他URL,因此在这种情况下不必使用ajaxsource

<script type="text/javascript">

//this is the datatable it brings data in json format from server
$( document ).ready(function() {
var selected=$("#mainschool_id option:selected").val();
//alert(selected);
$('#example').dataTable({
       "bProcessing": true,
             "ajax": {
            "url": "/nvs/system/modules/NVS.NLI/elements/trainingalldatatable.jsp",
            "data":{data:selected}

            },

               "search": {
                 "smart": false
               },
               "scrollX": true,
       "aoColumns": [
           { type: "text"},
           { type: "number"},
           { type: "text" },
           { type: "text" },
           { type: "text" },
                       { type: "text" },
                       { type: "text" },
                       {type:"text"},
                       { type: "text" },
                       { type: "text" },
                       { type: "text" },
                       {type:"text"},
                        {type:"text"}



              ]
      });
});
</script>

I hope it helps thanks. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM