javascript - How do I catch JSON parse errors with JQuery JSON calls? -
I am calling AJAX on a server which sometimes returns incomparable JSON. The server is not under my control, so I can not fix it.
function event function (evt) {$ ('div # status_bar'). Show (); $ AJAX ({url: 'http://buggyserver.com/api/', type: 'GET', data: {'mode': 'jason', 'q': 'get / data'}, data type: Jason ', success: update form}); } Function update form (back, position) {if (condition == 'success') {// update form here} $ ('div # status_bar'). Hide (); } When the invisible JSON returns, the updateForm function is not called.
How can I, on the client side, make sure that the last line of the updateForm function is asked to hide the status bar? I have tried to put the attempt {} catch {} client to both AJAX calls and update forms.
You can:
function event function (avt ) {$ ('Div # status_bar'). Show (); $ AJAX ({url: 'http://buggyserver.com/api/', type: 'GET', data: {'mode': 'jason', 'q': 'get / data'}, data type: Jason ', success: update form, complete: function () {$ (' div # status_bar '). Hide ();}}); } Function Update Form (Returned) {// Update Form Here} After the success complete callback fire, whether successful or not
Comments
Post a Comment