Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82788

Ajax call with parameters

$
0
0
Ive been messing around with this for a week, and I think I am going down the wrong path. I have a txt file that has the following data:

{
  "sEcho": 1,
  "iTotalRecords": "116",
  "iTotalDisplayRecords": "10",
  "aaData": [
{"ID":3,"AddressID":2,"ContactType":184,"Code":"Daily","FirstName":"Ed","LastName":"McCready"}, ...
   ]
}

This works fine with the following call:

        		        $('#ajaxTest').dataTable({
        		            "bJQueryUI": true,
        		            "bProcessing": true,
        		            "sPaginationType": "full_numbers",
        		            "iDisplayLength": 25,
        		            "sAjaxDataProp": "aaData",
        		            "sAjaxSource": "./jsonData.txt",
        		            "bServerSide": false,
        		            "aoColumns": [
                                { "mDataProp": "ID" },
                                { "mDataProp": "AddressID" },
                                { "mDataProp": "ContactType" },
                                { "mDataProp": "Code" },
                                { "mDataProp": "FirstName" },
                                { "mDataProp": "LastName" },
                            ]        		                    		                    		            
        		        });

I actually copied the json from what is being returned from a web method and pasted it into a text file to test. But when I try to directly grab the data from the server, I get errors. Here is what I have tried. Keep in mind that my web method is expecting a list of parameters.


        		        $('#ajaxTest').dataTable({
        		            "bJQueryUI": true,
        		            "bProcessing": true,
        		            "sPaginationType": "full_numbers",
        		            "iDisplayLength": 25,
        		            "sAjaxDataProp": "d",
        		            "sAjaxSource": "test.aspx/DoProc",
        		            "sServerMethod": "POST",
        		            "bServerSide": true,
        		            "fnServerData": function(sSource, aoData, fnCallBack) {
        		                $.ajax({
        		                    "type": "POST",
        		                    "url": sSource, //"test.aspx/DoProc",   
        		                    "contentType": "application/json; charset=utf-8",
        		                    "data": aoData, //'{"procName":"procGetAllContacts","parmsVals":"","procType":"Select"}',
        		                    "dataFilter": function(data) {
        		                        msg = eval('(' + data + ')');
        		                        msg = msg.d;
        		                        fnCallBack('{"sEcho":1,"iTotalRecords":20,"iTotalDisplayRecords":10,"aaData":' + msg + "}");
        		                    },
        		                    "error": AjaxFailed
        		                });
        		            },
        		            "fnServerParams": function(aoData) { aoData.push({ "procName": "procGetAllContacts", "parmsVals": "", "procType": "Select" }); },
        		            "aoColumns": [
                                { "mDataProp": "ID" },
                                { "mDataProp": "AddressID" },
                                { "mDataProp": "ContactType" },
                                { "mDataProp": "Code" },
                                { "mDataProp": "FirstName" },
                                { "mDataProp": "LastName" },
                            ]      
        		        });



I have tried about every combination and I usually get a 200 error. Sometimes I take out the fnServerParams and use the parameters as you see commented out for the data. Any insight would be appreciated. I feel like I am very close, but Im missing something.

Viewing all articles
Browse latest Browse all 82788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>