1👍
In the done
part you have:
.done(function(data) {
form.find(".success-msg").text(data);
});
But in the fail
you didn’t include the data
argument. You should include it if you want to use it:
.fail(function(data) {
// insert error msg to the form
});
Regarding the other question – if you know the reason for the fail – I think it’s better to response with 200
and inside the response to have a status: true/false
and the rest of the data. This way you can use different functions/behavior if you got some other error code (server not responding/server error/etc).
1👍
This might be late but I had this same issue recently and this is my solution.
.error(function(xhr){
var result = xhr.responseJSON;
form.find(".error-message").text(result.data);
});
You can always console log xhr.responseJSON to be sure what’s being returned.
- [Answered ]-Django Rest Framework: How to get value of the ForeignKey
- [Answered ]-Django image upload issue
- [Answered ]-Django 1.10 Delete large cascade querySet
- [Answered ]-Django template not displaying looped keys, values
Source:stackexchange.com