Skip to content

Instantly share code, notes, and snippets.

@phannam1412
Last active October 5, 2016 11:05
Show Gist options
  • Save phannam1412/73607d49dcb12fb237962d23ba534a20 to your computer and use it in GitHub Desktop.
Save phannam1412/73607d49dcb12fb237962d23ba534a20 to your computer and use it in GitHub Desktop.
Ajax request with javascript
<html>
<head></head>
<body>
<script type="text/javascript">
// Set up the request.
var xhr = new XMLHttpRequest();
// Open the connection.
xhr.open('POST', 'test-ajax-request.php', true);
// Set up a handler for when the request finishes.
xhr.onload = function () {
if (xhr.status === 200) {
alert('posted');
}
else {
alert('An error occurred!');
}
};
// Send the Data.
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('test1[]=test2&test1[]=test3');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment