Extract and Read Data from XML using AJAX and JavaScript
What is AJAX?
AJAX = Asynchronous JavaScript And XML.
AJAX is not a programming language.
AJAX just uses a combination of:
- A browser built-in
XMLHttpRequest
object (to request data from a web server) - JavaScript and HTML DOM (to display or use the data)
AJAX can be used for interactive communication with an PHP, .ASP, Databases, XML file,
Here i am showing use of AJAX for interactive communication with an XML file.
Inside my .xml
Inside xml file we use few tags (you can make your own tags) and i will call these tags value using AJAX (a part of Javascript) which will show my friend list and their details (For Example).
Inside .js we used few methods of AJAX :
new XMLHttpRequest()
- Creates a new XMLHttpRequest object
getResponseHeader()
- Returns specific header information
open(method, url, async)
- Specifies the request
Also we used few property of AJAX :
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"
For a complete list go to the Http Messages Reference
Why use AJAX?
AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
For more query visit w3schools AJAX
Hope this will help you <3
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.