Skip to content

Instantly share code, notes, and snippets.

@Shakil-Shahadat
Last active December 25, 2020 11:59
Show Gist options
  • Save Shakil-Shahadat/1f45458cca6953f67ebf to your computer and use it in GitHub Desktop.
Save Shakil-Shahadat/1f45458cca6953f67ebf to your computer and use it in GitHub Desktop.
Ajax POST request with data [ Obsolete, use fetch instead ]
let data1 = 'Hello World!';
let data2 = 'Hello Universe!';
let http = new XMLHttpRequest();
http.open( 'POST', 'post.php' );
http.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
http.send( 'data1=' + data1 + '&data2=' + data2 );
http.onreadystatechange = function()
{
if ( http.readyState == 4 && http.status == 200 )
{
console.log( http.responseText );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment