admin管理员组文章数量:1391960
I'm using the following code to get the dataa from the server:
$.getJSON('.svc/SampleMethod?callback=?', dd, function (data) {
alert(data);
});
From the server, I'm sending the byte array as response.
In firebug
, in Net > Response
tab, I get:
jQuery19101878696953793153_1365677709012([67,37,94,38,42,44,69,67,71,32,97,116,116,97,99,104,101,100,32,102,111,114,32,112,97,116]);
Also in Net > JSON
tab, I get data with several keys.
But how to get the data at alert(data);
; so that I process on that data.
I don't know, how this thing works.
Edit:
I tried this different approach:
$.ajax({
type: "GET",
dataType: "jsonp",
contentType: "application/javascript",
data: dd,
crossDomain: true,
url: ".svc/SampleMethod",
success: function (data) {
alert(JSON.parse(data));
},
plete: function (request, textStatus) { //for additional info
alert(request.responseText);
alert(textStatus);
},
error: function(request, textStatus, errorThrown) {
alert(textStatus);
}
});
But I got: parseerror
as alert.
I'm using the following code to get the dataa from the server:
$.getJSON('http://xxx.xxx.xxx.xx/SampleWebService/Service.svc/SampleMethod?callback=?', dd, function (data) {
alert(data);
});
From the server, I'm sending the byte array as response.
In firebug
, in Net > Response
tab, I get:
jQuery19101878696953793153_1365677709012([67,37,94,38,42,44,69,67,71,32,97,116,116,97,99,104,101,100,32,102,111,114,32,112,97,116]);
Also in Net > JSON
tab, I get data with several keys.
But how to get the data at alert(data);
; so that I process on that data.
I don't know, how this thing works.
Edit:
I tried this different approach:
$.ajax({
type: "GET",
dataType: "jsonp",
contentType: "application/javascript",
data: dd,
crossDomain: true,
url: "http://xxx.xxx.xxx.xx/SampleWebService/Service.svc/SampleMethod",
success: function (data) {
alert(JSON.parse(data));
},
plete: function (request, textStatus) { //for additional info
alert(request.responseText);
alert(textStatus);
},
error: function(request, textStatus, errorThrown) {
alert(textStatus);
}
});
But I got: parseerror
as alert.
-
data
is that array, isn't it (what do you get from the alert)? Just use it. – Bergi Commented Apr 11, 2013 at 11:11 - @Bergi, the problem is I don't get any alert. – mike44 Commented Apr 11, 2013 at 11:16
-
Hm. Do you get an error? Append
.fail(alert.bind(window));
, orconsole.log
the object that$.getJSON
returns. – Bergi Commented Apr 11, 2013 at 11:53 - @Bergi, No. Please see the update. – mike44 Commented Apr 11, 2013 at 12:15
-
1
Check your network tab whether the large response is plete. I've heard of cases where the server (or something in the munication channel) chops of very long responses. And if it's plete, maybe it really is invalid; let your debugger halt on scripting errors or post the response into a linter. Btw: You don't need
JSON.parse
with JSONP, as your callback gets passed an object literal not a JSON-string-literal! – Bergi Commented Apr 11, 2013 at 13:32
4 Answers
Reset to default 2From looking at the docs (I haven't tried this) you need to explicitly tell jQuery that you're making a JSONP call that will invoke the function that's returned. Something like this:-
$.ajax({
type : "GET",
dataType : "jsonp",
url : "http://xxx.xxx.xxx.xx/SampleWebService/Service.svc/SampleMethod",
success: function(data){
alert(data);
}
});
Function you are looking for is JSON.parse. Please try this code :
$.post("YouURL", { 'ParameterName': paramvalue }, function (Data) {
var data = JSON.parse(data);
});
Your response is a function call. If u define function name with name jQuery19101878696953793153_1365677709012 you can process the 'data' else from your server just send the json as a response to $.getJSON's callback to work
The problem was the data was very huge. I was sending array of around 10,00,000+ bytes. So instead I divided it into list of bytes (each having 1000 bytes) & then sent as response.
I don't know if this is the best solution, but it solved my problem. BTW, thanks to all for helping me.
本文标签: javascriptGetting data through jQuery ajax requestStack Overflow
版权声明:本文标题:javascript - Getting data through jQuery ajax request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744750746a2623159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论