Solved

$.getJSON does not work across domain with me?

Posted on 2011-09-21
12
293 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now