jQuery Ajax Request is Giving Error on Mobile in Asp.net MVC 4
I am using jquery 1.11.1 with Asp.net MVC I am requesting a $.ajax request to my MVC Controller Action and it is working fine on desktop but giving error on mobile version
My jQuery Ajax request is as follows:
$.ajax({
method: 'GET',
url: ajaxurl + 'GetListingByAjax',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
pagenumber: pageno,
currenturl: location.href
}),
dataType: 'json',
success: function (data) {
if (data.length > 0) {
$('#LoadMoreListings').show();
var FullHTML = GetListingHTML(data);
$('#loading').remove();
pageno++;
}
else {
$('#LoadMoreListings').hide();
$('#loading').text('No more listings to display');
}
},
error: function (a,b,c) {
alert('Exeception Description : '+c);
}
});
And My Controller Action is
public JsonResult GetListingByAjax(int pagenumber, string currenturl = "")
{
var ListingItemsList = new Listing().GetListingAjax(currenturl, pagenumber, 20, 0);
return Json(ListingItemsList, JsonRequestBehavior.AllowGet);
}
This is working fine on desktop and when I run it on mobile it gives me Internal Server Error then I checked the response in Chrome Emulator then it shows following error
The parameters dictionary contains a null entry for parameter 'pagenumber' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GetListingAjax(Int32, System.String)
Then I tried by changing method GET to POST but the error on mobile was same and on desktop it was fine
Can anyone help me please am I doing something in wrong way or i need to add anything extra in this code to be run on mobile
Please help me out thanks in advance
You are missing the pagenumber
parameter in your ajax URL:
url: ajaxurl + 'GetListingByAjax',
should be something like
url: ajaxurl + 'GetListingByAjax/2',
In that way the controller gets to make use of the parameter pagenumber
you've told it to require.
上一篇: 在Mvc中对控制器进行简单的Ajax调用