/    Sign up×
Community /Pin to ProfileBookmark

AJAX, JQuery, JSON with api help needed please.

Hi, last couple of days i had been search all over the Internet an trying to find the solution. But no use ? so i really need your help here.

I have basic knowledge with ajax and jquery. I am working with api which returns the info back to the browser as a json format. I wrote the code which connects to the api server and get the josn data successfully. But main problem is with the representation of the json data.

I have setup the local environment for the work but as you know firefox doesn’t show the info for some security reason. So i use ie8 for testing. In local environment the data represent ok. But when i upload the script into server ie have an error which says access denied? And also firefox have the json object null!

The platform i am using this is wordpress. Hopefully it not causing any problem.

here is the page i used the code: [url]http://citystir.com/shopping/[/url]
Here is the code:

in the header:

[CODE]
// jquery code
$(document).ready(function(){
var ywsid = “nP7LU8_uZABdb7A8U_dukQ”;
var url =”http://api.yelp.com/business_review_search?location=chicago&cc=US&limit=4&category=shopping&ywsid=”+ywsid;
var dom = “#shopping_reviews”;
callYelp(url, dom);
});
[/CODE]

In external js file.

[CODE]
function callYelp(url, domnode){
jQuery.getJSON(url, function(data){
jQuery(domnode).empty();
jQuery.each(data.businesses, function(i, data){
printHtml(data, i, domnode);
});
return false;
});
}

function printHtml(data, i, dom){
var review_no = 0;
var html = ” “;
html += “<a href=”+data.url+” title=”+data.name+”alt=”+data.name+”><img src=”+data.photo_url+” alt=”+data.name+”></a>”;
html += “<p>Total reviews: “+data.review_count+”<p>”;
html += “<img src=”+data.rating_img_url+” alt=”+data.avg_rating+”/>”;
html += “<p>”+data.address1+”</p>”;
html += “<p>”+data.address2+”</p>”;
html += “<p>”+data.address3+”</p>”;
html += “<p>Latest Review: “+data.reviews[review_no].text_excerpt+”</p>”;
html += “<p>By <a href=”+data.reviews[i].user_url+” title=”+data.reviews[review_no].user_name+”>”+data.reviews[review_no].user_name+”>></a></p>”;
html += “<p>Categories:”+get_items(data.categories);+”</p>”;
jQuery(html).appendTo(dom);
}

function get_items(items){
var cat = ” “;
for (i=0; i <items.length; i++){
cat += “<a href=”+items[i].search_url+” title=”+items[i].name+”>”+items[i].name+”</a>&nbsp;”;
}
return cat;
}
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @prionkor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...