how to make retry possible after AJAX error

how to make retry possible after AJAX error

bayenibayeni Posts: 57Questions: 8Answers: 0

If everything is used correctly in the editor, everything works fine with edit or create, but can you tell me what I have to call, if AJAX call throughs an error and I want to give the user another chance to correct the data an send again.
e.g. I used:

ajax: {
...
  error: function (xhr, error, thrown) { 
     alert ("The combination of name and company has to be unique");   
  }
 };     

But after I got the popup for the error and clicked ok, I can't send again the data with button Update or Create in editor window (it don't send anything anymore).
Thanks for information!

Answers

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited June 2017

    Is this the ajax option of an Editor config? If so, the docs ajax state that you can not override the the success or error ajax options as they are used internally.

    Ideally, the response from your ajax call should be as defined in the client/server protocol - https://editor.datatables.net/manual/server . When done like this Editor will automatically route the errors to the correct place, either a field or generic editor message.

    If your response is not quite in the correct format you can use the postSubmit event (I think that's the right one) and wiggle it into the correct format so Editor can process it as it is expecting to.

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

    If so, the docs ajax state that you can not override the the success or error ajax options as they are used internally.

    That was the case, but it is actually valid in Editor to do that now (1.6+). You can't in DataTables (yet). It looks like I forgot to update that document - sorry!

    However, it would only enter the error state if invalid JSON was returned from the server.

    @bayeni - What is the JSON you are returning. As @rduncecb says, if you return the JSON response with the error message Editor expects, it will show the message correctly and allow you to correct the error and then submit the value.

    Allan

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

    I've just checked the docs for ajax and it says:

    Prior to 1.6 the success and error options should not be overridden as these are used by Editor. Editor 1.6 will now recognise your methods and execute them after its own functions.

    Allan

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    Thank you both.
    I use an existing service and with wrong data I get back "500 internal server error". For a sucessfull update/create I get back a JSON record without "data" as keyword and it works, so is "error" as keyword necessary?

    The other possibility is to proove the data before sending, but I don't know how to do that from editor, I think like : editor.on('preSubmit', ( e, json, data, action ) {}), can I use data.name for the content of the name field?
    How have I to break sending the data in case of wrong data and alerting the user to give him a chance to correct the data before sending?

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    I have a question about the error format to you rduncecb and allan.
    If I try to create a response like
    {"error":"error message"}
    the button in editor can be used after changing field values again, but the message "error message" is not shown anywhere. In the format description on https://editor.datatables.net/manual/server it is error with type String.

    Is the created format wrong, I didn't see an example for an simple error on the page. I expect that the error message should be shown in div.DTE_Form_Error, is that correct?

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

    div.DTE_Form_Error, is that correct?

    Yes - your returned error statement looks absolutely correct.

    Could you give me a link to the page showing that issue please? I don't know why that wouldn't be working I'm afraid.

    Allan

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    unfortunetly it is an internal appication, not accessible in internet.
    An empty data record is not nessary (becuase it is not optional in the description) isn't it? I tried with empty data record, too.
    Would a debug information help?

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

    The debug trace would at least show me the version you are using. But I think if you are seeing this issue with the latest versions, then I really would need a test case showing the issue to be able to figure it out.

    Thanks,
    Allan

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    I tried to create debug information akasaj, I hope that shows something. I see in my TCP monitor that I got back {"error":"hugo"}, but in editor I get "a system error has occured (more information) with link http://datatables.net/tn/12. Is a special HTTP returncode expected to show the error text?

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

    Is a special HTTP returncode expected to show the error text?

    No. Any return code that gives valid JSON should work.

    Unfortunately the debugger will only show me the JSON from the DataTable data load, not Editor.

    The notes at the tech note you linked to show how to see what the server is returning. If you are getting that error, then its not valid JSON. Without being able to see it, I can't say what is triggering that. It could even be a UTF8 BOM which JSON parsers don't like.

    Allan

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    I attached a snapshot of the TCP monitor, you can see on the left side what the editor send to store and on the right side the response from the server

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    I don't know how I could create a test case with editor, because a server is necessary for that and my is not open from internet. With http://live.datatables.net/ I don't know how to use editor.

  • bayenibayeni Posts: 57Questions: 8Answers: 0

    with HTTP return code 200 or 202 it is working, but with 4xx, 5xx (e.g. at least 406, 510) it seems not to working.

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

    Ah! I've put the pieces together now. You are using Editor 1.5.2 which would indeed have a problem with this. The latest version, Editor 1.6.3 should work with this no problem.

    Allan

This discussion has been closed.