JSONP 在 ASP 上的第二次调用时不会返回结果。MVC & JQuery 解决方案



我已经在我的项目的这个链接上实现了解决方案,以具有jsonp功能:http://blogorama.nerdworks.in/entry-EnablingJSONPcallsonASPNETMVC.aspx

它在第一次调用时像魅力一样工作,但在第二次调用时它没有响应?

你有什么想法吗?

我的 json 调用是:

$.ajax({
    type: "GET",
    url: '../../askjson',
    data: { name_startsWith: name },
    cache: false,
    dataType: "jsonp",
    success: function (data) { }
});

控制器是:

[HttpGet]
[JsonpFilter]
public JsonResult askjson(string name_startsWith)
{
    // do stuff
    return Json(resultView, JsonRequestBehavior.AllowGet);
}
嗨,

Gorkem,您可以在jsonp上检查此代码项目解决方案

http://www.codeproject.com/Articles/223572/Calling-Cross-Domain-WCF-service-using-Jquery-Java

谢谢你们。

我已经跟踪了错误,它是一个 400 表示:请求超过了在 MaxQueryStringLength 定义的允许设置。

所以我在 <system.web> 下将以下内容添加到我的 web.config 中

 <system.web>
    <httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />

我也通过以下方式对<system.webServer>做了同样的事情:

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxUrl="10999" maxQueryString="2097151"  />

我的问题消失了!

最新更新