How to make this jquery function reusable?

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-03-30T09:46:49Z Indexed on 2010/03/30 9:53 UTC
Read the original article Hit count: 441

Filed under:
|
|
|

Hai this is my jquery function,

function getRecordspage(curPage, pagSize) {
    $.ajax({
        type: "POST",
        url: "Default.aspx/GetRecords",
        data: "{'currentPage':" + curPage + ",'pagesize':" + pagSize + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(jsonObj) {
            var strarr = jsonObj.d.split('##');
            var jsob = jQuery.parseJSON(strarr[0]);
            $.each(jsob.Table, function(i, employee) {
                $('<div class="resultsdiv"><br /><span class="resultName">' + employee.Emp_Name + '</span><span class="resultfields" style="padding-left:100px;">Category&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.Desig_Name + '</span><br /><br /><span id="SalaryBasis" class="resultfields">Salary Basis&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.SalaryBasis + '</span><span class="resultfields" style="padding-left:25px;">Salary&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.FixedSalary + '</span><span style="font-size:110%;font-weight:bolder;padding-left:25px;">Address&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.Address + '</span></div>').appendTo('#ResultsDiv');
            });
            $(".resultsdiv:even").addClass("resultseven");
            $(".resultsdiv").hover(function() {
                $(this).addClass("resultshover");
            }, function() {
                $(this).removeClass("resultshover");
            });
        }
    });
}

In my page i have this jquery script,

$("#lnkbtn0").click(function() {
                 getRecordspage(1, 5)
            });

And my page has

<a ID="lnkbtn0" class="page-numbers">1</a>
<a ID="lnkbtn1" class="page-numbers">2</a>
<a ID="lnkbtn2" class="page-numbers">3</a>
<a ID="lnkbtn3" class="page-numbers">4</a>

How to make other link buttons to call this function with diff curPage parameter...

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about anchor