415 (Unsupported Media Type) during post call using editor edit option

415 (Unsupported Media Type) during post call using editor edit option

susilsusil Posts: 5Questions: 0Answers: 0
edited January 2014 in Editor
Hi, I am using a testing the API before fully incorporating it. Just did a prototype and it worked fine with editable data table. But posting the edit failed, during edit call from editor I get the 415 ( Unsupported Media Types ) . I have set on the server side to accept json/object. The on JS I have following;
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": {
"create": "service/appcreate",
"edit": "POST service/appedit",
"remove": "DELETE service/appdel?id=_id_"
}
It seems to call the right url during edit service/appedit. I see it being sent as text/html on developer tool (chrome), network/type column. But I do not see any data. Is there a way to force these create/edit/remove to provide json datatype ?
Also who will error handling be done on each of these cases.?
Any Help, Thank You

Replies

  • susilsusil Posts: 5Questions: 0Answers: 0
    Just wanted to provide console output from developer tool;
    POST http://localhost:8080/accessadmin/service/applicationformcreate 415 (Unsupported Media Type) jquery-2.0.3.min.js:6
    x.support.cors.e.crossDomain.send jquery-2.0.3.min.js:6
    x.extend.ajax jquery-2.0.3.min.js:6
    f.defaults.ajax dataTables.editor.js:203
    f._submit dataTables.editor.js:190
    f.submit dataTables.editor.js:156
    n.TableTools.j.editor_edit.d.extend.formButtons.fn dataTables.editor.js:227
    (anonymous function) dataTables.editor.js:111
    x.event.dispatch jquery-2.0.3.min.js:5
    y.handle jquery-2.0.3.min.js:5
  • susilsusil Posts: 5Questions: 0Answers: 0
    Also, I am using "$.fn.dataTable.Editor" but looking at the doc, I see "$.fn.Editor" being used in rest example. Are these different APIs requiring different JS file/apis ?
  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    Last point first :-). It should be `$.fn.dataTable.Editor` like the example here: https://editor.datatables.net/release/DataTables/extras/Editor/examples/REST.html .

    > I have set on the server side to accept json/object

    And only json/object? Unless you are explicitly setting the MIME type that Editor is sending as part of the Ajax request, it will just be sending the jQuery / browser default, which for my browser at least is `application/x-www-form-urlencoded; charset=UTF-8` .

    If you want to send a different MIME header, you'll need to use the `ajax` option - https://editor.datatables.net/options/#ajax to make the Ajax call.

    Regards,
    Allan
  • susilsusil Posts: 5Questions: 0Answers: 0
    Thank you for your response. I set it to accept */* on the server side, but still I am getting the same 415 error.
    My curl post request with json data is posted correctly with statement like this;
    curl --user user:pass -X POST -HContent-type:application/json -HAccept:application/json --data '[{"attributeid":1,"applicationid":1,"groupid":1,"sectionid":1,"attributename":"adminfirstname","displayname":"First Name","displayorder":1,"enabled":1,"isrequired":1,"attributetypeid":1,"sectionname":"Sction 1","sectionorder":1,"grouporder":1,"attributetypename":"text","datatype":"string","groupname":"Step1","defaultvalue":null,"optionvalues":null,"capturedept":0,"shownextsectionvalue":0,"sectiondefaultvisibility":0,"value":null,"accessdeptcode":null}]' http://localhost:8080/test/service/applicationformcreate

    This works fine. But If I am to use ajax based call (which allows me to define mimetype accept/content) from datatable editor for create/edit/remove then how would one do it such a way that the error coming from serve is captured and presented. I tried to use "event" for example "onEdit" to make post call to the server but the call does not get into "onEdit" block as tall. Any example on this would be supper. The doc pointed out just show how to make separate ajax call if need be but does not tell how to tie them to create/edit/remove actions. I really like the api and would like to make it work. Any doc or example/pointer ?

    Thanks
  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    > then how would one do it such a way that the error coming from serve is captured and presented

    Simply define an `error` handler. You need to use `$.ajax` if you want to make your own Ajax call, so you have complex control over every aspect of that Ajax call - including the error handler, which could be used to show an error message - possibly with the Editor `message()` API method.

    I'm afraid I don't know what would be causing the 415 error if the MIME header is accepted. Are you using IIS? That's outside the range of my expertise I'm afraid, all I can suggest is checking the server's error log.

    Allan
  • susilsusil Posts: 5Questions: 0Answers: 0
    Hi Allan, Thank you for your suggestion. I had not been able to look into the issue for sometime. But I found the issue 2 days back and resolved it. Basically json data construct had additional attributes that made it to be giving 415 error. Thanks for the api. I just bought it.
  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    Hi - great to hear you got a solution and thanks for purchasing :-)

    Allan
This discussion has been closed.