Solved

$.getJSON does not work across domain with me?

Posted on 2011-09-21
12
294 Views
Last Modified: 2012-05-12

the following code does not work with me:
$.getJSON(url,
         function (data) {
             if (data.results[0]) {
                 alert('hi');
 
                 $.each(data["Rows"], function (i, el) {
                     $("#target").append("<a href=\"" + el[1] + "\">" + el[2] + "</a><br />");
                 })
 
                 //container.html(data);
             } else {
                 var errormsg = '<p>Error: could not load the data.</p>';
                 container.html(errormsg);
             }
         });

 And here is the url that I pass: http://www.somedomain.com/page.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&jsoncallback=xyz 
And here is the JSON that returned back

xyz({"Columns":["id","Article_Url","Article_Title","date","num"],
 "Rows":[
   ["5bb93b83-d129-4ca9-8999-ed54910b824d","97.74.67.146/test.html","test","\/Date(1316189236173)\/",25],
   ["82d62b61-d96b-489a-ae91-008b897db553","97.74.67.146/testx.html?xx=x","test","\/Date(1316256259490)\/",11],
   ["97aaf346-1146-429e-bc5a-fcfa4b2d934b","97.74.67.146/testx.html","test","\/Date(1316255702510)\/",4],
   ["2fea1222-e254-4db9-a68e-5129a0d87e8e","97.74.67.146/qn_news_story_s.asp?storyid=1093442005","Oman invests USD3.8b in constructing dry dock","\/Date(1316188504010)\/",2],
   ["82fe900d-eefe-4540-87a4-1fe6057234a7","http://www.menafn.com/qn_news_story.asp?StoryId={83510500-a24b-4f87-9bf1-3985134ee4b6}","Title 1","\/Date(1315411910897)\/",1],
   ["217f8e33-8723-4de3-9afc-438d7172f90e","http://www.menafn.com/qn_news_story_s.asp?StoryId=1093437815&src=MOEN","Title 1","\/Date(1315411969900)\/",1]
 ]
} )

 What Im doing wrong?!
 
0
Comment
Question by:Sindibad_123
  • 7
  • 5
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36574663
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36574778
or using your url : http://www.somedomain.com/page.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&jsoncallback=xyz 

var url = "http://www.somedomain.com/page.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&jsoncallback=xyz";
$.getScript(url);

         function xyz(data) { 
             if (data.results[0]) { 
                 alert('hi'); 
 
                 $.each(data["Rows"], function (i, el) { 
                     $("#target").append("<a href=\"" + el[1] + "\">" + el[2] + "</a><br />"); 
                 }) 
 
                 //container.html(data); 
             } else { 
                 var errormsg = '<p>Error: could not load the data.</p>'; 
                 container.html(errormsg); 
             } 
         }

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36574834
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 82

Expert Comment

by:leakim971
ID: 36575181
another one :
url = "http://www.somedomain.com/page.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&callback=?";
$.getJSON(url, function(data) { xyz(data); });

test page : http://jsfiddle.net/uWMSj/
0
 

Author Comment

by:Sindibad_123
ID: 36575265
You are the man.
0
 

Author Comment

by:Sindibad_123
ID: 36575361
Now the call succeeded but I got the error "could not load data"!

Here is the returned json:
xyz({"Columns":["id","Article_Url","Article_Title","Last_Red_Date","hitnum"],"Rows":[["5bb93b83-d129-4ca9-8999-ed54910b824d","97.74.67.146/test.html","test","\/Date(1316189236173)\/",25],["82d62b61-d96b-489a-ae91-008b897db553","97.74.67.146/testx.html?xx=x","test","\/Date(1316256259490)\/",11],["97aaf346-1146-429e-bc5a-fcfa4b2d934b","97.74.67.146/testx.html","test","\/Date(1316255702510)\/",4],["2fea1222-e254-4db9-a68e-5129a0d87e8e","97.74.67.146/qn_news_story_s.asp?storyid=1093442005","Oman invests USD3.8b in constructing dry dock","\/Date(1316188504010)\/",2],["82fe900d-eefe-4540-87a4-1fe6057234a7","http://www.menafn.com/qn_news_story.asp?StoryId={83510500-a24b-4f87-9bf1-3985134ee4b6}","Title 1","\/Date(1315411910897)\/",1],["217f8e33-8723-4de3-9afc-438d7172f90e","http://www.menafn.com/qn_news_story_s.asp?StoryId=1093437815&src=MOEN","Title 1","\/Date(1315411969900)\/",1]]})


whats wrong with it?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36575383
which code
the better one for you is $.getSript
0
 

Author Comment

by:Sindibad_123
ID: 36575433
yes I used getScript
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36575438
your json object is fine
the code is fine
you've an error somewhere else
0
 

Author Comment

by:Sindibad_123
ID: 36576449
well I give up i cannot find whats going on so here is my url that I call:
url= http://www.emailtorssfeed.com/core/getpopstories.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&d=30&callback=xyz


I used jsfiddle.net and got same result!
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36576676
your json only have Columns and Rows as direct "members"
You test :  if (data.results[0]) {
there's no results member

check this : http://jsfiddle.net/PDzKV/
url = "http://www.emailtorssfeed.com/core/getpopstories.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&d=30&callback=xyz";

    $.getScript(url);

    function xyz(data) { 
        if (data.Rows.length>0) {
                 $.each(data["Rows"], function (i, el) { 
                     $("#target").append("<a href=\"" + el[1] + "\">" + el[2] + "</a><br />"); 
                 }) 
        }
        else {
            var errormsg = '<p>Error: could not load the data or no rows.</p>';
            container.html(errormsg);
        } 
    }

Open in new window

0
 

Author Comment

by:Sindibad_123
ID: 36576910
thank you man.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java script read and write file - save as location 8 42
What am I doing wrong with this Lightbox widget? 6 33
jquery datepciker end date add 6 days 6 34
jqury 17 28
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question