简体   繁体   English

jQuery Ajax请求在Asp.net MVC 4中的移动设备上出现错误

[英]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 我在Asp.net MVC上使用jquery 1.11.1我向我的MVC Controller Action请求一个$ .ajax请求,它在桌面上工作正常,但在移动版本上却报错

My jQuery Ajax request is as follows: 我的jQuery Ajax请求如下:

$.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 这在台式机上运行良好,当我在移动设备上运行时,它提示我内部服务器错误,然后我在Chrome模拟器中检查了响应,然后显示以下错误

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) 参数字典包含用于方法'System.Web.Mvc.JsonResult GetListingAjax(Int32,System.String)的非空类型'System.Int32'的参数'pagenumber'的空条目。

Then I tried by changing method GET to POST but the error on mobile was same and on desktop it was fine 然后我尝试通过将GET方法更改为POST进行尝试,但移动设备上的错误相同,而台式机上的错误也很好

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: 您在ajax URL中缺少pagenumber参数:

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. 这样,控制器就可以利用您告诉它要求的参数pagenumber

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM