How to dynamically load directive in angularjs through json?

What is the best way to get JSON data via JavaScript with cookie authentication?

  • I'm building an application with Ruby on Rails. The application is a Javascript application that get data by JSON calls from the `api` application. It also provide the cross domain authentication for the application itself and the `api`. I handle the cross domain authentication via making both application cookies with same secret session key and same name e.g. `_app_an_api_session`. Now, I'll write down the senario and I'll show you when it fails. The application domain is `domain.local` the api domain `api.domain.local` Lets say that `api.domain.local/me` is a protected page. When I open it i got `unauthenticated` When I go to the application and `sign in` and go to `api.domain.local/me` again, I can see the data in it. [Pass] [it works also for the opposite actions]. The problem is, for example, after `sign in` I want to load `api.domain.local/me` contents [JSON data] in `domain.local`, I can see in the console that the `status` is `(canceled)`. In addition for debugging sake. I tried to see the `env` variable on each request to the `api`. So, when I access the `api.domain.local/me`directly, I can see the cookies hash in the console, else if it via the real application, there's no cookies/sessions at all. So, how to make it possible to done this right?

  • Answer:

    I apologize if I'm not reading your question right, but... if you are serving json, then you don't need cross-domain authentication.  Just authenticate to your json domain, and your json will be cross-domain through the script tag.  http://en.m.wikipedia.org/wiki/JSONP

Bradford Mar at Quora Visit the source

Was this solution helpful to you?

Other answers

If a cookie is set to domain.local, it can also be read by subdomains, such as api.domain.local. Are you sure that 'unauthenticated' is an error caused by the lack of a session key?

John Paul

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.