-
May 21st, 2012, 02:17 AM
#1
Thread Starter
Addicted Member
jQuery function return value
I am very new to this, I made this function:
Code:
function getID(user){
$.getJSON('https://twitter.com/users/'+user+'.json?callback=?',
function(data)
{
$('#userid').html(data.id_str);
});
}
Works well, but I want that instead of modifying the value of #userid I return a value, I tried this:
Code:
function getID(user){
$.getJSON('https://twitter.com/users/'+user+'.json?callback=?',
function(data)
{
return data.id_str;
});
}
But it makes me return to the function within which it is, not getID.
Solutions?
Thanks!
Last edited by *PsyKE1*; May 22nd, 2012 at 05:00 AM.
-
May 21st, 2012, 12:36 PM
#2
Re: jQuery function return value
getJSON() is an asynchronous method, which I don't think can be used in that way. But getJSON() is essentially just a wrapper for jQuery's more generic ajax() method, which allows you to set its async property (it notes that JSONP cannot support synchronous operation, but it doesn't look like you need that). From there, you could get the jqXHR object that is returned by ajax() and parse that for your result.
-
May 21st, 2012, 08:14 PM
#3
Re: jQuery function return value
Now - I'm curious - why are you calling a twitter service like that?
Would they want to know you are doing that??
-
May 22nd, 2012, 04:30 AM
#4
Thread Starter
Addicted Member
Re: jQuery function return value
getJSON() is an asynchronous method, which I don't think can be used in that way. But getJSON() is essentially just a wrapper for jQuery's more generic ajax() method, which allows you to set its async property (it notes that JSONP cannot support synchronous operation, but it doesn't look like you need that). From there, you could get the jqXHR object that is returned by ajax() and parse that for your result.
Ok, thanks, I'll investigate.
Now - I'm curious - why are you calling a twitter service like that?
Would they want to know you are doing that??
I just get the id of a twitter user.
Thanks! :P
-
May 22nd, 2012, 07:05 PM
#5
Re: jQuery function return value
You might be interested in the Twitter API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|