0

I have this simple page that just needs to show contents that is loaded from an external url (ajax request, response in json format)

I should say I'm a AngularJS newbie.

I've googled a bunch and found different ways of doing this and couldn't manage to determine which is the correct/simple/up-to-date way to achieve this.

My 2 challenges -

  1. Making the AJAX request run on startup (I can load the page before that happens and just load the contents one the ajax request finishes. Maybe show a 'Loading..' indicator)
  2. Doing a ajax request correctly.

Here is my attempt. I know that the ajax request is never made because its not setup correctly.

2 Answers 2

1

You are getting into .error function: http://jsbin.com/oDUsuVA/3/edit

For jsonp your response should be something like:

callback([
{
    "title":"License Title 1",
    "licenseUrl":"http://cnn.com",
    "licenseText": " test"
}]);

Edit: You can simply do .get() request too, but if you had to use jsonp request interface, you would have to correct response.

A Jsonp request always wraps the logic into a json callback wrapper function.

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

Comments

0

I just did $http.get instead of your $http.jsonp and it did work for me.

1 Comment

As simple as that... Thanks

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.