Get error 400 bad request when using Ajax POST Jquery
Dung Do Tien
Mar 15 2021
412
I have a project with Asp.Net Core. On the Contact page after filling in all information and click Submit button, I submit that form by using Ajax. You can see the code below:
var form = $('form:first');
$.post(form.attr('action'), data, function (response) {
if (response !== null) {
if (!response.success) {
alert("something error!!!!");
} else {
document.location.href = response.linkDirect;
}
}
else {
alert("something error!!!!");
}
});
I test it on Windows it's working fine but when deploying into Linux it throws an error 400 bad requests.
Thanks for any suggestion.
Have 1 answer(s) found.
-
N-2
Nguyen Truong Giang Mar 15 2021
I got same the error. I change to use
$.ajax
and set more optiondataType: "json"
It worked for me.$.ajax({ url: form.attr('action'), type: "POST", dataType: "json", data: data, async: true, success: function (response) { } });
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.