How to change alert message for json parsing error?

How to change alert message for json parsing error?

adromiladromil Posts: 53Questions: 4Answers: 0

Is there a way to change the Alert Message when json parsing encounter errors?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Modify the source :-). There is no external API to change that message as it is intended for developers only to indicate that something is wrong and should take action before deploying to customers.

    Allan

  • adromiladromil Posts: 53Questions: 4Answers: 0

    I'm just wondering if there would be any in the near future?
    What I encountered using dataTables 1.10 may be on my ends fault or error. I would like to share it anyway for your information.

    What happened is every time I reload the page where dataTable is displayed, I inconsistently receiving the json parsing error alert message- sometime it doesn't, sometimes it does. The MySQL DB Server is on the same locahost, and there are no inconsistent error an the MySQL Server's end.

    I tried to use your suggestion from the other discussion using:

                $.fn.dataTableExt.sErrMode = 'throw';
    

    And as I tried to check the console logs, it throws exception for numerous time during the page is reloading.

    The I tried to use JavaScript Server-Sent Events (SSE) and call the instance variable of the dataTable inside the EventSource onmessage() function for receiving feeds from server. And it gradually shows the instances that the json parsing error thrown.

    I also tried to check and double check the PHP Script of the JSON for the server-side AJAX Source and browse it on the browser and tested the JSON format and I found nothing peculiar.

    Thus, I decided to ask you about this topic.

    Or maybe you can provide me inputs for better error handling I guess.

    Best regards and more power!

    Adromil

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    If you are getting the JSON formatting error message, you need to look at what the server is returning and fix it so that it always returns valid json.

    Allan

  • adromiladromil Posts: 53Questions: 4Answers: 0
    edited May 2014

    I already did that and simulated the call on PHP script. And the Server is returning the correct JSON format, and still I am receiving the json parsing error.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    If you are receiving the error about invalid JSON - the server is returning invalid JSON. The error is computed by jQuery and I have no reason to believe that they've got it wrong.

    Please link to the page so we can take a look at it.

    Allan

  • adromiladromil Posts: 53Questions: 4Answers: 0
    edited May 2014

    You may check this out from a test server, I created a dummy page for your checking.

    http://58.69.142.44/revlon/list.php

    You may check the console to see the thrown exception.

    Best regards

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Did you see that your server is returning a MySQL error before the JSON?

    <br />
    <b>Warning</b>: mysql_pconnect(): MySQL server has gone away in <b>C:\xampp\htdocs\revlon\json\listdt.php</b> on line <b>45</b><br />

  • adromiladromil Posts: 53Questions: 4Answers: 0

    My apologies, the fault is on my end. I modified the host address, it is using the external public IP instead on the localhost. I just copied it from an external script I made for production. I think that was causing the JSON error.

    What I did to resolve the issue is to reside my MySQL Database server where my Web Application is hosted, maybe since the database server is encountering issues that's why it's returning invalid json previuously

    Thank you @tangerine for your inputs, I appreciate it a lot.

    Also, thanks to @allan for your continued support and assistance to people like us.

This discussion has been closed.