[英]Getting data through jQuery ajax request
I'm using the following code to get the dataa from the server: 我正在使用以下代码从服务器获取dataa:
$.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: 在
firebug
,在Net > Response
选项卡中,我得到:
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. 同样在
Net > JSON
选项卡中,我获得了包含多个键的数据。
But how to get the data at alert(data);
但是如何使数据处于
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));
},
complete: function (request, textStatus) { //for additional info
alert(request.responseText);
alert(textStatus);
},
error: function(request, textStatus, errorThrown) {
alert(textStatus);
}
});
But I got: parseerror
as alert. 但我得到了:
parseerror
警报。
From 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. 从查看文档(我还没有尝试过),您需要明确告诉jQuery您正在进行JSONP调用,该调用将调用返回的函数。 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. 您正在寻找的功能是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
如果您使用名称jQuery19101878696953793153_1365677709012定义函数名称,则可以从服务器处理'data',只需发送json作为对$ .getJSON回调的响应即可工作
The problem was the data was very huge. 问题是数据非常庞大。 I was sending array of around 10,00,000+ bytes.
我发送了大约10,00,000多个字节的数组。 So instead I divided it into list of bytes (each having 1000 bytes) & then sent as response.
所以我把它分成了字节列表(每个都有1000个字节),然后作为响应发送。
I don't know if this is the best solution, but it solved my problem. 我不知道这是否是最佳解决方案,但它解决了我的问题。 BTW, thanks to all for helping me.
顺便说一句,感谢所有人的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.