ajax reload has invalid json response

ajax reload has invalid json response

OrbitallOrbitall Posts: 3Questions: 1Answers: 0

When loading the page the table data is loaded no problems using the ajax options. But when using the reload code supplied below i get a invalid json response.

I'm not sure how because (according to JSONLint) I get valid JSON response when accessed from the page with the same php path specified in the data tables ajax options. I also have other tables on the page that use the same reload function without problems.

How can I resolve this issue so I can use this code within my table reload function for all the tables?

$('#verifiedItems').DataTable().ajax.reload();

alert: DataTables warning: table id=verifiedItems - Invalid JSON response
console: ajax is null - jquery.dataTables.js:2592:4
debug code: ucekah

Thanks in advance

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    The response from the server is:

    < script > console.log('Debug Objects: INVALID-ROOM'); < /script>
      
      
     
    <!DOCTYPE html>
    <html lang="en">
     
    <head>
     
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
     
        <title>HMS - Admin Items</title >
     
    <!--
    ... etc
    

    That's not valid JSON, hence the error.

    I'm afraid I don't know why your server-side script would be returning that.

    Allan

  • OrbitallOrbitall Posts: 3Questions: 1Answers: 0

    This doesnt make much sense to me, what you have displayed is the start of the php page the table is located on, shortly after the title is the table with an id of verifiedItems, not the ajax response.

    Is the table not using the same options to populate data on page load(which was successful) as it is on reload?

    DT OPTIONS

      options =    
      {   
            ajax: "php/data/output-items.php?startOutput=verified",
            language: 
            {
                "emptyTable": "No verified items"
            },
            aoColumnDefs: 
            [
                { "sClass": "col-hazards", "aTargets": [4] },
                { "sClass": "col-info", "aTargets": [5] }
            ],
            aoColumns: 
            [
                {
                    "className":      'details-control',
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": ''
                },
                { mData: 'name' },
                { mData: 'cas' },
                { mData: 'unit' },
                { mData: 'hazard' },
                { mData: 'infomation'}
            ]
        };
    
    

    AJAX RESPONSE

    This is the output I get when manually putting the php url (shown in ajax section above) into the browser, this shows 1 item in table:

    {"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[{"DT_RowId":"4","name":"Spermine","cas":"71-44-3","unit":"g","hazard":[" [\"corrosive\"] "],"infomation":"<\/span><\/a>","hazInfo":[{"icon":" [\"corrosive\"] ","code":"H314","statement":"Causes severe skin burns and eye damage"}]}]}
    

    Am I missing somthing?

    Why is the ajax.reload() not being able to access the ajax response supplied from the url from the options?

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin
    edited May 2016

    All I'm able to go on is the debugger code you gave above and the fact that you state you are getting the invalid JSON error. If you load your debugger trace and for the #vertifiedItems table click the "Server interaction" option (its right at the bottom of the page).

    As you will be able to see there the response is not valid JSON.

    To be able to see anything further, or even just to confirm that, I would need a link to the page so I can check it manually.

    Allan

  • OrbitallOrbitall Posts: 3Questions: 1Answers: 0

    Sorry the site is not public, I was hoping you / someone had seen similar symptoms, I will try and find a solution myself.

    BTW I am very impressed with your extensive plugin and documentation. Also surprised with your prompt support :) I will purchase once I experiment more, in my second project!

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    I was hoping you / someone had seen similar symptoms

    All I can really say is that the JSON error is occurring because invalid JSON is being returned. I can't really say why that is the case though.

    Thanks for your kind words :-). Sorry I can't help further here!

    Allan

This discussion has been closed.