Friday, November 2, 2012

jQuery Get HTML Response Example

The jQuery Get() ajax method supports HTML, XML, JSON and Text type responses sent by the server. In this post we shall see on how to process HTML data returned from the server using the jQuery Get() method.

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

$.get("<Server URL>", successHandlerFunction(…));

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


.aspx Page (Client Side)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>jQuery Ajax Load</title>
    <script type="text/javascript" src="JavaScript/jquery-1.7.2.js"></script>
    <script
        type="text/javascript"
        language="javascript">
        $(document).ready(function() {
            // Get HTML Response data from the Server
            $('#btnGetHTML').click(function(event) {
                event.preventDefault();
                $.get("AjaxData.html", function(result) {
                    $("#divHTML").html(result);
                    }
                );
            });         
        });
    </script>                 
</head>
<body>
    <form id="frmAjax" runat="server">
    <table border="1">
        <tr>
            <td><b>Action</b></td>
            <td><b>Response</b></td>
        </tr>
            <tr valign="middle">
                <td>
                    <asp:Button
                        ID="btnGetHTML"
                        runat="server"
                        Text="Get HTML" />
                </td>
                <td align="center">
                    <br /><div id="divHTML"></div> 
                </td>
            </tr>
           
    </table>
    </form>
</body>
</html>

.AjaxData.html (Server Side)

<table border="1">
    <tr>
        <td><b>Name</b></td>
        <td><b>Age</b></td>
        <td><b>Address</b></td>
    </tr>
    <tr>
        <td>John</td>
        <td>35</td>
        <td>125. E.Spring Creeks, OH</td>
    </tr>
    <tr>
        <td>Harry</td>
        <td>23</td>
        <td>121 Highway, Plano TX</td>
    </tr>   

Search Flipkart Products:
Flipkart.com

No comments: