onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
When using POST, you send the query string as a parameter of the send() method, instead
of joining it on to the base URL, like this:
// Call the server page to execute the server-side operation
xmlHttp.open("POST", "http://localhost/ajax/test.php", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send("param1=x¶m2=y");
The two code samples should have the same effect. In practice, there are a few differences
between POST and GET that you should know about:
??? Using GET can help with debugging because you can simulate GET requests with a web
browser, so you can easily see with your own eyes what your server script generates.
??? POST is required when sending large blocks of data, which cannot be handled by GET.
??? GET is meant to be used for retrieving data from the server, while POST is meant to submit
changes. In the real world, it??™s good to obey these rules; otherwise, strange things
can happen. For example, search engines send GET requests to read data from the Web,
but they never post any data. If you use GET to submit changes and a search engine
becomes aware of the address of the server script, that search engine could start modifying
your data??”and you certainly don??™t want that!
The minimal implementation of a function named process() that makes asynchronous
server calls using GET looks like this:
function process()
{
// Call the server to execute the server-side operation
xmlHttp.
Pages:
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521