Error during sAjaxSource call

Error during sAjaxSource call

dangesantdangesant Posts: 6Questions: 0Answers: 0
edited July 2013 in General
Hi, I'm a young italian developer at first time on this forum.
WellI 'm making a local website and when I run this script
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "http://46.37.13.177:7710/WebClinicalDataAPI/GetDocumentsToValidate",
"aoColumns": [
{ "mData": "owner" },
{ "mData": "size" },
{ "mData": "status" },
{ "mData": "title" },
{ "mData": "grade" }
]
} );
} );
[/code]
I obtain this error :
[quote] "XMLHttpRequest cannot load http://46.37.13.177:7710/WebClinicalDataAPI/GetDocumentsToValidate?_=1372782614035. Origin null is not allowed by Access-Control-Allow-Origin." [/quote]

Thank to everyone help me!!

Replies

  • aaronwaaronw Posts: 89Questions: 3Answers: 4
    So, short story is that you cannot make an AJAX call to a different domain. Look at http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain for some ways to get around this restriction.
  • dangesantdangesant Posts: 6Questions: 0Answers: 0
    @aaronw .... first of all , thank you to answer at my question.
    Second, if I do this (a simple ajax call in the same script):
    [code]
    $.ajax({
    type:"GET",
    url:"http://46.37.13.177:7710/WebClinicalDataAPI/GetDocumentsToValidate",
    dataType:"jsonp",
    timeout:"20000",
    crossDomain : true,
    data: {format :"jsonp"},
    success:function(json) {
    console.log ("json");
    }}});[/code]
    it's work fine!! Why?
  • dangesantdangesant Posts: 6Questions: 0Answers: 0
    ok.. I have found the problem. In second case , is set [code]crossDomain : true[/code],
    question : How I can set the same in DataTable??
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Currently you'd need to use a method like this: http://datatables.net/release-datatables/examples/server_side/jsonp.html .

    DataTables 1.10 will include an `ajax` option which makes this somewhat easier.

    Allan
  • dangesantdangesant Posts: 6Questions: 0Answers: 0
    edited July 2013
    Hi Alla, first of all thank you to answer me.
    I've done what you said me ..
    [code]
    $('#tab').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "http://46.37.13.177:7710/WebClinicalDataAPI/GetDocumentsToValidate?format=jsonp",
    "fnServerData": function( sUrl, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "url": sUrl,
    "data": aoData,
    "success": fnCallback,
    "dataType": "jsonp",
    "cache": false
    } );
    }
    } );
    [/code]

    but now the error is :
    [quote]Uncaught TypeError: Cannot read property 'length' of undefined at jquery.dataTables.js:2038[/quote]

    what's wrong?
  • dangesantdangesant Posts: 6Questions: 0Answers: 0
    edited July 2013
    the line is this :
    [quote]for ( var i=0, iLen=aData.length ; i
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    DataTables expects a property called aaData which contains the data. Your JSON object doesn't have that. It has the data in GetDocumentsToValidate.docs.doc. You might want to use sAjaxDataProp to change aaData to what you need.

    Allan
  • dangesantdangesant Posts: 6Questions: 0Answers: 0
    ok but I dont understand the meaning of :
    [quote]
    "url": sUrl,
    "data": aoData,
    "success": fnCallback,
    "dataType": "jsonp",
    "cache": false
    [/quote]

    I must to put the value of the field or the name???
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    What value of what field?

    The parameters for the object you highlighted are for the jQuery Ajax call and don't really have that much to do with DataTables. See: http://api.jquery.com/jQuery.ajax/

    Allan
This discussion has been closed.