0

I'm trying to access an API via jquery with ajax , here's my code

$(document).ready(function(){
function kimonoCallback(data) {
   var ticker = '<ul id="webticker">';
   var url = data.results.collection[i].alaune; 
   $.each(url,function(i, news ){       
     ticker += '<li>';
     ticker += '<a href="'+ news.href+ '">';
     ticker += '<img src="img/ticker_sep.png" alt="sep"/>';
     ticker += '"'+ news.text +'" </a></li>';
   });
   ticker += '</ul>';
   $('#tickernews').html(ticker);
  }



$.ajax({
        "url":"https://www.kimonolabs.com/api/d7dujppi?apikey=xxxxxxxxxxxxxxxxxxxx&callback=kimonoCallback",
        "crossDomain":true,
        "dataType":"jsonp"
    });

});

when i try to see the results in the webpage nothing come up no error in the console. so how do i make the request and display the text my webpage.

check the api here

4
  • Does the server from which you are requesting the data allow cross-domain requests? The headers returned by the API link you gave don't have any origin headers set. Commented Jul 4, 2014 at 16:00
  • yeah the server accept CORS Commented Jul 4, 2014 at 16:07
  • it gives reponse with json but not with jsonp so it is not allowing jsonp i think Commented Jul 4, 2014 at 16:11
  • i fixed it , i add to add the CORS domain in order for the server to answer the request. Commented Jul 4, 2014 at 16:59

1 Answer 1

1

Working example: http://jsfiddle.net/6jU3b/5/

Call your method in the success method of the ajax response rather than trying to execute it when returned from the server.

I also changed your $.each statement a bit to reflect the updated object (you changed it from collection to collection1 while I was working on it :{

$(document).ready(function(){
    $.ajax({
        url:"https://www.kimonolabs.com/api/d7dujppi?apikey=94d5808efe01f5eab40a5027c54bf86f",
        crossDomain:true,
        dataType:"jsonp",
        success: function(data) {
            console.log(data);
            kimonoCallback(data);
        }

    });

function kimonoCallback(data) {
   var ticker = '<ul id="webticker">';
   var url = data.results.collection1; 
   $.each(url,function(key, value){       
     ticker += '<li>';
     ticker += '<a href="'+ value.alaune.href + '">';
     ticker += '<img src="img/ticker_sep.png" alt="sep"/>';
     ticker += '"'+ value.alaune.text +'" </a></li>';
   });

   ticker += '</ul>';
   $('#tickernews').html(ticker);
 }

});
Sign up to request clarification or add additional context in comments.

1 Comment

No problem! Glad we got it figured out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.