Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
$(document).ready(function () { 

    $.ajax({
 
        type: 'GET',
 
        url: 'https://js.i-parcel.com', [^]
 
        timeout: 15000,
 
        success: function (data) { alert('Connected to i-parcel.'); },
 
        error: function (XMLHttpRequest, textStatus, errorThrown) { alert('Error:\r\n' + textStatus); }
 
    });
 
});
Posted
Updated 28-Jan-13 23:24pm
v2

1 solution

Put it into a separate function and use the OnClientClick attribute in your button's tag.

JavaScript
<script type="text/javascript">

    $(document).ready(function () {

    });

    function callAjax()
    {
       $.ajax({
            type: 'GET',
            url: 'https://js.i-parcel.com', [^]
            timeout: 15000,
            success: function (data) { alert('Connected to i-parcel.'); },
            error: function (XMLHttpRequest, textStatus, errorThrown)
            { alert('Error:\r\n' + textStatus); }
       });
    }

</script>



ASP.NET
<asp:button runat="server" id="btnClick" onclientclick="callAjax(); return false;" text="Click Here" />
 
Share this answer
 
v2
Comments
[no name] 29-Jan-13 5:30am    
+5
k@ran 29-Jan-13 5:56am    
what is the use of xmlns:asp="#unknown" here..
Nick Fisher (Consultant) 31-Jan-13 4:08am    
Sorry, the HTML editor on this site seems to sometimes insert these tags when you paste code snippets in the response. This tag was not there in the original code, and I've removed it now.
vinodkumarnie 1-Feb-13 5:51am    
good solution..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900