?
Solved

$.getJSON does not work across domain with me?

Posted on 2011-09-21
12
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

752 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