Last active
October 5, 2016 11:05
-
-
Save phannam1412/73607d49dcb12fb237962d23ba534a20 to your computer and use it in GitHub Desktop.
Ajax request with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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