1

I have got a web service which gets list of users from an external system and returns as json. and I call that webservice via jquery ajax.; I have placed ajax code below

 $.ajax({
        type: "GET",
        url: webMethod,
        data:"",
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        success: function(msg) {
            alert(msg.d);
        },
       error: function(e) {
         alert(e);
        }
    });

Even though, the output is in correct format, the output I get from jquery.ajax seems to be wrong. it returns big chunk of the data correctly, then adds "; (" and continues to show the output.

Basically, the output is ("around %75 of data");(rest of the data) which makes my json invalid. I am not sure whether it is related to the maxJasonLenght or not but I also set it to the maximum. there seems to be a limitation on how much data you can get from web service as if I add more data to that json, the break down point changes.

Sample Output


[{"UserName":"a.b","FullName":"a b"},{ Many other users},{"UserName":"c.d","FullName":"c d"},{"UserName":"e.f",);jsonp1364397526212("FullName":"e f"}, {"UserName":"g.h","FullName":"g f"},{other users}}

do you have any idea why I am having this issue? Thanks

AnarchistGeek
  • 3,049
  • 6
  • 32
  • 47
  • 1
    Can you show some sample output – smk Mar 27 '13 at 18:20
  • Sounds like something the web service itself might be doing. Is this a service you control? Or is it a third-party service? – Matt Burland Mar 27 '13 at 18:35
  • Can we see your ajax code? Also, try not to use arrays as top level in your JSON, specially for web services since that is highly insecure. Unless you don't care about that data being read by a third party. – Ryoku Mar 27 '13 at 18:38
  • Mmm, have you tried using firebug or something like that to see if the error is in the data being received or in the way the ajax method interprets it? – Ryoku Mar 27 '13 at 18:39
  • If its a size issue, then I dont think its something you can fix on client side since the response size is determined on server. – smk Mar 27 '13 at 18:43
  • @MattBurland I have written the service, it has been working so far without any problem, but recently we added more people to that output, and it is broken – AnarchistGeek Mar 27 '13 at 19:31
  • @Ryoku I have added the ajax code, web service and the application which we call this service are in same server. using json or jsonp does make any difference on the problem above. Also, I have used Fiddler to to see the traffic, and did not see any error, data is retrieved successfully, but the format is not valid. – AnarchistGeek Mar 27 '13 at 19:35
  • @smk but if I test that web service on my browser, I get the data correctly. jquery.ajax is doing something funny... – AnarchistGeek Mar 27 '13 at 19:37

1 Answers1

0

Do you set the crossDomain option to TRUE? If I'm not wrong, if you set the crossDomain option to TRUE, the response would be JSON-P.

Look at this post so you can figure out how to handle the response: What is JSONP all about?

I hope it would help!

Community
  • 1
  • 1
adiego73
  • 189
  • 1
  • 3
  • 13