Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jquery - Browser response size limit

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-service. I have checked getJson() is giving proper response object. But still my callback function is not called. Firebug is saying that it's(firefox) response size is exceeded.

Can anybody tell me whats the maximum browser response size limit that the standard browser e.g (firefox, ie) handle and how to deal with the problem?

Here is the code snippet for the same.

 //Wrapper call to the actual getJson call
 function getResponse() {
    var localService = new getServiceProxy("SearchData.asmx");
    localService.invoke("Search", "", "successcall");
 }

 //getJson call
 function getServiceProxy(serviceUrl) {
     var _I = this;
     this.serviceUrl = serviceUrl;

     // *** Call a wrapped object
     this.invoke = function(method, data, callback, error) {

         if (data == "") {
             var url = _I.serviceUrl + "/" + method + "?output=json&callback=?";
         }
         else {
             url = _I.serviceUrl + "/" + method + "?" + data + "&output=json&callback=?";
         }
         $.getJSON(url, function(arg) {       
             var evalstr = callback + "(" + JSON.stringify(arg) + ");";
             eval(evalstr);
         });
     }
 }

 //success callback function
 function successcall(multiSearchResponse) {
     //use the response.
 }

any help will be highly appreciated.

Thanks Subrat.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...