Ajax - Technical Introduction |
|
request to the server.
For this we use two methods of Http request object’ class:
i) open()
ii) send()
These methods can be used as given in the code snippet below:
xmlHttp.open(‘POST’, ‘time.php’, true);
xmlHttp.send(‘name=abc&age=25’);
open():
This method can take three parameters:
- First Parameter:
Name of HTTP request method (GET, POST, HEAD etc.)
- Second Parameter:
URL of the requested page to read data from.
- Third Parameter:
- A boolean value (TRUE, FALSE), to specify whether the request is asynchronous or
synchronous.
If it is set to TRUE the request is set as asynchronous i.e. the browser continues the execution of
JavaScript function even response has not been received yet from the server.
If it is set to FALSE then request is set to synchronous. In that case the browser waits for the
response of the server, which you may not prefer in case of fetching lot of data from the server.
Send():
This method is used to send data to the server with the request. If you don’t want to send any
then you can write code as below:
xmlHttp.send(null)
If HTTP request method is of type “POST” then send() method can be used to send any data to
the server as param and value pair. For example,
“name=abc”
You can send as much data to the server by creating the query string like this:
“name=abc&age=25”
NOTE:
If HTTP request method is of type “POST” then we have to change the MIME type of the request
otherwise the server will not accept such data. So, you have to follow the code snippet given below:
xmlHttp.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’); 4) Working with the Response data:
|
|
Apr 2008 | Java Jazz Up | 13 |
|
|
|
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 ,
70,
71,
72,
73,
74,
75,
76,
77,
78,
Download PDF |
|
|
|