Wednesday, November 14, 2012

jQuery getScript Example

jQuery provides various methods like ajax, load, get, post, getJSON, getJSON etc  to make an Ajax call. In this post we shall see on how to use the getScript() method to make an Ajax call.

The following example receives a getScript data from the server and executed it in the browser

.aspx Page (Client Side)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>jQuery Ajax getJSON</title>
    <script type="text/javascript" src="JavaScript/jquery-1.7.2.js"></script>
    <script
        type="text/javascript"
        language="javascript">
        $(document).ready(function() {
            // Get Script Response data from the Server
            $('#btnGetScript').click(function(event) {
                event.preventDefault();
                $.getScript("AjaxData.js");
            });
        });
    </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="btnGetScript"
                        runat="server"
                        Text="Get Script" />
                </td>
            </tr>
    </table>
    </form>
</body>
</html>

.AjaxData.js(Server Side)

alert("Hi, i am from the Server");

Related Post
jQuery getJSON Method
jQuery getJSON Example
jQuery getScript Method
jQuery getScript Example

Search Flipkart Products:
Flipkart.com

No comments: