Calling a function / database update using Ajax via Jquery

Im creating a simple "Was this useful?" form with Yes and No objects- Using webforms.

I need the submission to be done via ajax using jquery, to prevent a user from voting multiple times on the same page.. currently i have two methods Like_Click and Dislike_click in the C# code behind the page in question.

Can anyone give me some pointers on or a link to any suitable walkthroughs for simple ajax via jquery (I'm new to ajax!)

Ive looked at using the [WebMethod] identifier on each of the methods but do not really understand this method fully.



You are probably looking for jQuery's post function. Check out the examples. You'll want to do something along the lines of:

$('.myForm').submit(function(){ //define a handler for the submit event of the form
    $.post($(this).attr('action'), {useful: true}); //send data via ajax
    return false; //prevents the form from submitting via a normal web request

You can try something like below

 <script type="text/javascript">
    $(function () {
        $('#btnSubmit').click(function () {
            var like = $('#Like').val();
            var dislike = $('#Dislike').val();
            if (name != '' && email != '') {
                        type: 'POST',
                        url: 'Home.aspx/UpdateDB',     //UpdateDB is declared as WebMethod 
                        async: false,
                        data: "{'like':'" + like + "','dislike':'" + dislike + "'}",
                        contentType: 'application/json; charset =utf-8',
                        success: function (data) {
                            var obj = data.d;
                            if (obj == 'true') {
                                alert("Data Saved Successfully");
                        error: function (result) {
                            alert("Error Occured, Try Again");

Webmethod is shown below

public static string UpdateDB(string like, string dislike) 
    //Add your stuff

take a look more details here Call WebMethod from jquery in ASP.NET


 ? Calling a WebMethod using jQueryAjax "GET"
 ? AJAX to web method not returning JSON
 ? JQuery ajax call web method cannot set datatype: json
 ? AJAX Call in ASP.NET not Firing Server Side Method
 ? Web method not called from ajax post
 ? Async Function Not Getting Called
 ? Async Function Not Getting Called
 ? Async Function Not Getting Called
 ? Calling async method and TaskScheduler in async/await
 ? Visual Studio throwing an error on called async function from test code