| ajax | |
| without loading the page u can send the data to server | |
| and get from server | |
| ajax means | asychronous javascript and xml |
| ajax just uses a browser built in object | |
| xmlhttprequest | |
| browser sent to server and get from server without page loading | |
| when browser sent to server based on event mentioned | |
| like browser loads | |
| or page refreshs | |
| keyup | |
| mouse up | |
| syntax for creating xml http request object | |
| all browsers have built in object, | |
| variable = new XMLHttpRequest(); | |
| older borwsers | |
| variable = new ActiveXObject("Microsoft.XMLHTTP"); | |
| code to know it has this object or not | |
| if (window.XMLHttpRequest) { | |
| // code for modern browsers | |
| xmlhttp = new XMLHttpRequest(); | |
| } else { | |
| // code for old IE browsers | |
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
| } | |
| objects or functions | |
| new XMLHttpRequest() | Creates a new XMLHttpRequest object |
| abort() | Cancels the current request |
| getAllResponseHeaders() | Returns header information |
| getResponseHeader() | Returns specific header information |
| open(method, url, async, user, psw) | Specifies the request |
| method: the request type GET or POST | |
| url: the file location | |
| async: true (asynchronous) or false (synchronous) | |
| user: optional user name | |
| psw: optional password | |
| send() | Sends the request to the server |
| Used for GET requests | |
| send(string) | Sends the request to the server. |
| Used for POST requests | |
| setRequestHeader() | Adds a label/value pair to the header to be sent |
| function or object properties | |
| onreadystatechange | Defines a function to be called when the readyState property changes |
| readyState | Holds the status of the XMLHttpRequest. |
| 0: request not initialized | |
| 1: server connection established | |
| 2: request received | |
| 3: processing request | |
| 4: request finished and response is ready | |
| responseText | Returns the response data as a string |
| responseXML | Returns the response data as XML data |
| status | Returns the status-number of a request |
| 200: "OK" | |
| 403: "Forbidden" | |
| 404: "Not Found" | |
| statusText | Returns the status-text (e.g. "OK" or "Not Found") |
Sunday, 14 June 2020
ajax introduction
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment