0

Although the submitted values get saved in the db just fine, the editable form remain open, its borders turn red (as something is wrong) and below I see "OK" message.

This is the script code part that deals with one of my columns:

    j('.status').editable({
    url: '/process',
    title: 'Promijeni status',
    ajaxOptions: {
        dataType: 'json'
    }
});

I'm coding in Codeigniter so the controller calls the model. In my model there's just a simple update statement, with no "return". Also, in the controller there's nothing that specifically sets the response status code. But I suspect the "OK" comes from the status code "200 OK".

If so, why everything is behaving like an error occurred? The form needs to be closed and new value should be loaded.

developer10
  • 1,450
  • 2
  • 15
  • 31
  • Does the AjaxOptions have a success method? If it does, put a breakpoint on, make sure it's hitting. And then doe your logic in that function. – Christopher Marshall Apr 10 '13 at 20:00
  • I removed that part as I thought it was supposed to deal with the errors. It goes like this: success: function(response, newValue) { if(!response) { return "Unknown error!"; } if(response.success === false) { return response.msg; } } – developer10 Apr 10 '13 at 20:10
  • I'm not sure how to achieve that "logic", ie. to update old with the new value? – developer10 Apr 10 '13 at 20:10
  • 1
    Yes! if response.success === true, put your code to hide form in this function. – Christopher Marshall Apr 10 '13 at 20:11
  • Thanks. However, that sounds like a workaround? The docs say if successful the script shouldn't return anything. So, I suppose the form should close by itself. Anyway, until I find out if that's the proper way to do it, I'll make it work as you suggested! Thanks a lot! – developer10 Apr 10 '13 at 20:16

1 Answers1

1

Thanks to this question: Why does $.ajax call for json data trigger the error callback when http status code is "200 OK"? I learned that possible cause of my problem was the fact the JSON data that was being returned from controller was malformed (or similar to that) so despite the fact the response status code was "200 OK" the error was being triggered.

So in my controller I set a dummy array: echo json.encode($myArr) and now the form hides on submit and new value is being loaded.

Community
  • 1
  • 1
developer10
  • 1,450
  • 2
  • 15
  • 31