Monday, October 22, 2012

jQuery Ajax XML Response Example

jQuery supports different types of responses data types which are sent by the server as a result of processing Ajax request, the various types of data supported are HTML, XML, JSON and Text. In this post we shall see on how to process XML data returned from the server using jQuery.

The syntax for receiving and processing XML response is as follows.

    url: "AjaxData.xml",
    cache: true,
    dataType: "xml",
    success: function(result) {…}

The following example receives a XML format data from the server and displays the data in a DIV tag in the browser.

.aspx Page (Client Side)
<html xmlns="" >
<head runat="server">
    <title>jQuery Ajax</title>
    <script type="text/javascript" src="JavaScript/jquery-1.7.2.js"></script>
        $(document).ready(function() {
            // Get XML Response data from the Server
            $('#btnGetXML').click(function(event) {
                var nameList = "";
                    url: "AjaxData.xml",
                    cache: false,
                    dataType: "xml",
                    success: function(result) {
                        $(result).find("Name").each(function() {
                            nameList = nameList + $(this).text() + "
    <form id="frmAjax" runat="server">
    <table border="1">
                    Text="Get XML"/>
                <div id="divXML"></div> 

AjaxData.xml (Server side)
<?xml version="1.0" encoding="utf-8" ?>
      <Address>125. E.Spring Creeks, OH</Address>
      <Address>121 Highway, Plano TX</Address>

Run the Application and click on the btnGetXML button, notice that the request is processed and the XML data sent by the server is parsed and displayed in the Browser.

Related Post
jquery ajax method
jquery ajax get example
jquery ajax post example
jquery ajax html response example
jquery ajax xml response example
jquery ajax json response example
jquery ajax text response example

Search Flipkart Products:

No comments: