Search code examples
ajaxwebmethod

Ajax calling WebMethod


I have created Accrodions dynamically and inside each pane is a link button. I have assigned a value to the ID of the link button. what I want to accomplish is that when I click on a link button in one of my pane I want to use the ID' value as the parameter.

My Ajax:

function FireThisEvent() {
    var Value;

        $("lnkCopy").click(function(event) {Value = (event.target.id);})
        alert(Value);
        alert(lnkCopy.val());
        $.ajax({
            type: "POST",
            url: "frmSchemeSetup.aspx/sbGetData",
            data: '{sdPreNo: Value}',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "JSON",
            timeout: 10000,
            success: function() {
                alert("YEAH!!!");
            },
            error: function(xhr, status) {
                alert(status + " - " + xhr.responseText);
            }
        });

    }

How can I accomplish this?

This is where I add the event to my link button

lnkCopy.Attributes.Add("onclick", "FireThisEvent()")

Solution

  • I manage to get my Ajax to call my WebMethod with the help of this following post.