简体   繁体   中英

error 400 bad request with AJAX form

JS:

function submitForm(){
var data = {
    name: _("#name").value,
    email: _("#email").value,
    message: _("#message").value
}
var output = JSON.stringify(data);
var ajax = new XMLHttpRequest();
    ajax.open( "POST", "/src/scripts/parser.php" );
    ajax.setRequestHeader("Content-Type", "application/json'");
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4 && ajax.status == 200) {
            console.log('success')
        } else {
            console.log('fail')
        }

    }
    ajax.send( output );
console.log(output)

}

When im trying submit form, i have error:

400 Bad Request Your browser sent a request that this server could not understand.

Can somebody help me? Thanks anyway :)

The key here is this statement: 'that this server could not understand'. This usually indicates that something is wrong on the server. But it could also be that your url is wrong. Either...

  1. parser.php does not exist
  2. parser.php exists in a different folder (other than 'src/scripts')
  3. There is a url re-write module on the server that obfuscates the physical path of parser.php
  4. parser.php returns a 400 error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM