Browser response size limit

后端 未结 3 547
陌清茗
陌清茗 2020-12-21 11:26

I am calling my cross domain web-service through a getJson() call from jQuery. As my response object size is pretty big, i have used the maximum JSon size for my web-servic

相关标签:
3条回答
  • 2020-12-21 12:04

    One thing that looks kind of weird is the callback function:

     $.getJSON(url, function(arg) {       
         var evalstr = callback + "(" + JSON.stringify(arg) + ");";
         eval(evalstr);
     });
    

    Since you are using JSONP (due to the request being cross-domain) the responding service should return a JavaScript like:

    jQueryGeneratedUniqueCallbackName12345({my: 'data', foo: 'bar'});
    

    So the arg argument is the actual JavaScript object. You should not need to stringify and then eval it. Simply use it as it is, i.e.:

     $.getJSON(url, function(data) {       
         console.log(data.foo);
     });
    

    Quite a while ago I posted about the inner workings of JSONP on my blog if you are interested in more details.

    0 讨论(0)
  • 2020-12-21 12:18

    Ive been through this once in a project, and what I recall was that IE has a limit of 2083 characters for both POST and GET requests. FF has a larger limit, but not limitless.

    http://support.microsoft.com/kb/208427

    0 讨论(0)
  • 2020-12-21 12:20

    Maybe you want your $.getJSON part look as follows:

    $.getJSON(url, function(arg) {       
        callback.apply(null, JSON.stringify(arg));
    });
    
    // Or more simply
    
    $.getJSON(url, function(arg) {       
        callback(JSON.stringify(arg));
    });
    

    Some more info about apply: MDN Docs


    UPDATE: Before that you could also change the getResponse function to:

    function getResponse() {
        var localService = new getServiceProxy("SearchData.asmx");
        localService.invoke('Search', '', successcall);
    }
    
    0 讨论(0)
提交回复
热议问题