Level 14 Level 16
Level 15


10 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

GET Requests (code)
xmlhttp.open("GET","demo_get.asp",true);\nxmlhttp.send();\n––In this you may get a cached result, to avoid this, add a unique ID to the URL:––\nxmlhttp.open("GET","demo_get.asp?t=" + Math.random(),true);\nxmlhttp.send();
xmlhttp.open("GET","demo_get2.asp?fname=Henry&lname=Ford",true); xmlhttp.send();
If you want to send information with the GET method, add the information to the URL:
xmlhttp.open("POST","demo_post.asp",true); xmlhttp.send();
A simple POST request:
xmlhttp.open("POST","ajax_test.asp",true); xmlhttp.setRequestHeader("Content–type","application/x–www–form–urlencoded"); xmlhttp.send("fname=Henry&lname=Ford");
To POST data like an HTML form, add an HTTP header with setRequestHeader(). Specify the data you want to send in the send() method:
Asynchronous – True or False?
AJAX stands for Asynchronous JavaScript and XML, and for the XMLHttpRequest object to behave as AJAX, the async parameter of the open() method has to be set to true:\n\nxmlhttp.open("GET","ajax_test.asp",true);
When using async=true, specify a function to execute when the response is ready in the onreadystatechange event:\n––––Example––––\nxmlhttp.onreadystatechange=function() {\n if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText;…
To use async=false, change the third parameter in the open() method to false:\n––––\nxmlhttp.open("GET","ajax_info.txt",false);\nUsing async=false is not recommended, but for a few small requests this can be ok.\n––––\nRemember that the JavaScript will NOT continue to exec…
AJAX – Server Response
To get the response from a server, use the responseText or responseXML property of the XMLHttpRequest object.
responseText Property
If the response from the server is not XML, use the responseText property.\n––––––––––––––––––––––––\nThe responseText property returns the response as a string, and you can use it accordingly–––––Example–––––\ndocument.getElementById("myDiv").innerHTML=xmlhttp.responseText;
responseXML Property
If the response from the server is XML, and you want to parse it as an XML object, use the responseXML property–––––––––\nxmlDoc=xmlhttp.responseXML;\ntxt="";\nx=xmlDoc.getElementsByTagName("ARTIST");\nfor (i=0;i<x.length;i++) {\n txt=txt + x[i].childNodes[0].nodeValue + "<br />"; }\ndocument.getElementById("myDiv").innerHTML=txt;