How to convert data to Integer which came with GET/POST from server to jquery function.
1) Those lines belong to server , and they are send to jquery script
line = json.dumps([1])
return line
2) This little code returns fetched result as json from the server , well at least i think its a json objects.
function lol() {
$.getJSON("http://help.me.plz:12345/test",function(result){
return result
});
}
3) So how do i convert value which comes from lol() to int ?
while (data.length < totalPoints) {
开发者_开发百科 var prev = data.length > 0 ? data[data.length - 1] : 50;
var y = lol();
data.push(y);
Debug : Thats what i basically get from firebug
Headers Response HTML [1] <--- SO it is send
Response Headersview source
Date Tue, 03 May 2011 09:11:05 GMT
Content-Length 3
Content-Type text/html
Server TwistedWeb/8.1.0
Its a dump of the last list i need to get, but i get undefined instead of numbers.
[[0, undefined], [1, undefined], [2, undefined] ....
I tried to fetch content with $.ajax() , i tried to use parseInt() on lol , basically on everything .... I am kind of lost :D I am sure it is easy . Yet my stupidity makes me ask for help ....
Ajax calls are asynchronous by default, so you can't return the value in a function. You'd have to do something like this:
$.getJSON("http://help.me.plz:12345/test", function(result){
var y = result; //Now we don't call lol()
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50;
data.push(y);
...
}
});
Hope this helps. Cheers
精彩评论