I have the following code which sends post data to my form and alerts the expected result, however I'm finding it hard to save this as a variable I can use outside the function, can anyone offer any help?
<script>
var http = new XMLHttpRequest();
var url = "form.php";
var params = "name=test";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.(params);
</script>