I'm loading data using a page scroll function. When I hard code the data line in my function everything works ok
For example this works sortby is set to "asc"
data: '{pageIndex: ' + pageIndex + ', sortby: "asc" }',
This doesn't work and I get undefined message
data: '{pageIndex: ' + pageIndex + ', sortby: '+ sortby +' }',
I have set an alert in the function and the value of var sortby does equal asc the alert box pops up when I scroll to the bottom of the page which is correct.
But it's not getting passed and causing the undefined error
This is what I have:
<script type="text/javascript">
var pageIndex = 1;
var pageCount;
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
GetRecords();
}
});
function getdropdownlistSelectedItem(sender, args) {
var raddropdownlist = $find('<%=RadDropDownList1.ClientID %>');
var selecteditem = raddropdownlist.get_selectedItem().get_value() || "asc";
return selecteditem;
}
function GetRecords() {
var sortby = getdropdownlistSelectedItem();
alert('Sortby: ' + sortby);
pageIndex++;
if (pageIndex == 2 || pageIndex <= pageCount) {
$("#loader").show();
$.ajax({
type: "POST",
url: "categorypage.aspx/GetCustomers",
// data: '{pageIndex: ' + pageIndex + ', sortby: "asc" }',
data: '{pageIndex: ' + pageIndex + ', sortby: '+ sortby +' }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
}
Can someone please show me how to pass this value correctly?
Thanks.
