Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a html page and i want to call method from a class using jquery.
Please note it down that there is no code behind page, its an html page and the method need to be called from class.
Posted
Comments
frostcox 21-Nov-14 17:27pm    
I would use a HttpHandler for this task, you can perform seemless operations with no effort at all, if you need a code sample I am happy to supply.

You would use the jQuery .ajax method: http://api.jquery.com/jQuery.ajax/[^]
 
Share this answer
 
Yes, you need to ajax call to make that work. So if that is independent class library, you need to create asp handler or web service out of that , so that ajax call can be made to handler / web service , which in turn will talk to class - method.
 
Share this answer
 
You need to use Web Method for this.....
check this..

JavaScript
<script type="text/javascript">
function ShowCurrentTime() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/abc",
        data: '{n: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert(response.d);
        }
    });
}
function OnSuccess(response) {
    alert(response.d);
}
</script>



C#
[System.Web.Services.WebMethod]
public static string abc(string n)
{
    return n;
}


Calling the method abc of default.aspx or you can call any web services method...

you can also check this link...
http://asp-arka.blogspot.in/2014/01/webmethod-in-aspnet-using-jquery-and.html[^]
 
Share this answer
 
Comments
Sumit Bhargav 21-Nov-14 17:44pm    
Hi there,
Thanks for the response.
I would like to say that there is no code behind page as you mentioned in your solution "default.aspx", it's an html page and i have simple class into which i have created a web method. Now i want to call that method using jquery from my html page. Please read the question.
Arkadeep De 22-Nov-14 2:01am    
i thing u didn't check the solution properly..i also mention about the web services.
just use a web service to code the web method....
Sumit Bhargav 22-Nov-14 6:46am    
I dont want to use a web service, i have a class and into which i have created a web method.

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