473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Undefined value returned by Ajax!

I am trying to get all Following IDs using Twitter API. Now on Load function am trying to alert the IDs array (FollowingArray) which returned by GetFollowing.

I've test the value of array inside the function , but it looks OK. When i try to alert it appears as undefined.

Expand|Select|Wrap|Line Numbers
  1. function Load()
  2. {
  3.     alert(GetFollowing("hatem"));
  4. }
  5.  
  6. function GetFollowing(ScreenName)
  7. {
  8.     var Following = $.ajax (
  9.  
  10.         {
  11.             url: "https://api.twitter.com/1/following/ids.json?cursor=-1&screen_name=" + ScreenName,
  12.             dataType:"jsonp",
  13.             timeout:10000,
  14.             async:false
  15.         }
  16.  
  17.     );
  18.  
  19.  
  20.     var FollowingArray = new Array();
  21.  
  22.     Following.success
  23.     (
  24.         function(Follow)
  25.         {
  26.             i = 0;
  27.             while(Follow["ids"][i])
  28.             {
  29.                 FollowingArray[i] = JSON.stringify(Follow["ids"][i]);
  30.                 i++;
  31.             }
  32.         }    
  33.     );
  34.  
  35.     Following.fail
  36.     (
  37.         function()
  38.         {
  39.             alert("Error!")
  40.         }
  41.     );
  42.  
  43.     Following.complete
  44.     (
  45.         function()
  46.         {    
  47.             return FollowingArray;
  48.         }
  49.     );
  50. }
  51.  
Jun 18 '12 #1
6 2201
Dormilich
8,658 Expert Mod 8TB
I think it doesn’t work because of the SOP (Same Origin Policy).
Jun 18 '12 #2
The value look OK when alerting it inside the function. But when we try to get by return fails !
Jun 18 '12 #3
Dormilich
8,658 Expert Mod 8TB
1) jqXHR.success() is deprecated
2) jqXHR.complete() is an event, returning from an Event does almost nothing
3) synchronous AJAX in jQuery note:
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false is deprecated.
Jun 18 '12 #4
Then, What is the solution ? !
Jun 18 '12 #5
Dormilich
8,658 Expert Mod 8TB
use FollowingArray. it should already contain the needed values.
Jun 18 '12 #6
I will make local service using PHP to get the needed data using normal ajax request. I think this may helps !
Jun 18 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gene Mat | last post by:
Hi, I'm trying to build a simple Perl program to get a list of newsgroups. Here's what I have... #!/opt/local/bin/perl use Net::NNTP; $nntp = Net::NNTP->new("nntp.perl.org",Debug,10);...
2
by: Guinness Mann | last post by:
Greetings, I asked this question over on the ADO.NET newsgroup and couldn't scrape up an answer. I realize that it is more of an ADO question than an SQL Server question, but I'm hoping there...
0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
6
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
0
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
6
by: David N | last post by:
Hi All, What is a best way to handle an undefined value object class that returned from a function. I have a function that call the ADO.NET ExecuteScalar() function and returns the object to...
3
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did...
5
by: Steven Prasil | last post by:
I have a C# program with an if statement similar to if (obj.myvar != Undefined.Value) { ...... } When I test it in the CSharp CLR debugger this debugger does not recoginze that the value is...
9
by: noor.fatma | last post by:
Hi all, if I declare a function as one returning int and do not return anything from the function ,what will it return? for example. the following function returns the value of sum correctly....
9
by: DanielJohnson | last post by:
I am wondering where does the value returned by main goes. Suppoes main returns some number say 42, where is it stored. Supposed a shell script call a C program and the program returns the value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.