Get error 400 bad request when using Ajax POST Jquery

Dung Do Tien Mar 15 2021 1224

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.

Get error 400 bad request

Thanks for any suggestion.

Have 1 answer(s) found.
  • N

    Nguyen Truong Giang Mar 15 2021

    I got same the error. I change to use $.ajax and set more option dataType: "json" It worked for me.

        url: form.attr('action'),
        type: "POST",
        dataType: "json",
        data: data,
        async: true,
        success: function (response) {
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close