How does $http.jsonp() work

InfinitePrime

Here is an example of a .json file:

[
  {
     "name":"Jon Skeets"
  },

  {
     "name":"Bill Joy"
  }
]

If this json file is obtained as:

$http.jsonp(pathToFile).then() {
     ... 
}

It returns a 404. There is nothing wrong with pathToFile I have verified it with curl, wget and the browser. But the problem is with jsonp() having to fetch .json files with the above structure. $http.get() can parse .json files with the above structure. But JSONP cant. It needs a dictionary at the top level and not an array.

To demonstrate this, I have created this firebase: https://blazing-fire-6512.firebaseapp.com/name.json

fetch the link in your browser or wget and it works. Try fetching it with Angular here and it returns 404 Request failed.

Frank van Puffelen

Firebase hosting does not support JSONP. It doesn't handle the callback parameter that is used to evaluate JSONP callbacks across origins.

Say you store this JSON at URL http://example.com/name.json:

{ "name":"Jon Skeets" }

If you access the URL http://example.com/name.json you get back exactly that JSON. And that is precisely what $http.get does.

When a server supports JSONP, it accepts a callback parameter. In such a case the URL ends up http://example.com/name.json?callback=displayName and the response is:

displayName('{ "name":"Jon Skeets" }');

This allows JSON data to be retrieved across origins, which is the whole reason for JSONP's existence.

Firebase's dynamic data servers support JSON. Firebase hosting does not.

Some possible solutions:

  1. If you're storing the JSON file and the application on Firebase hosting, you can just use $http.get.
  2. Since you control the JSON file, you can also simply put a function name inside name.json
  3. Store the JSON file at a host that supports JSONP. I often put them in Github Gists.
  4. Store the data structure in a Firebase hierarchical database, and not on their hosting servers

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JSONP with remote URL does not work

From Dev

JSONP with remote URL does not work

From Dev

How does http://to./ work?

From Dev

How does this HTTP request work?

From Java

How does HTTP file upload work?

From Dev

Flask HTTP Basicauth - How does it work?

From Dev

How does http://a/%%30%30 work?

From Dev

Xamarin MvvmCross Http Request : How does this work?

From Dev

How does HTTP POST work in Polymer?

From Dev

$http and factory - how does this pattern work?

From Dev

How does http/ssh protocol work?

From Dev

how to change the headers for angularjs $http.jsonp

From Dev

Angular $http jsonp: how to parse through data

From Dev

How does http connection pooling work in work in Jersey?

From Dev

How does chunked downloading work in http/2 (or better what is the equivalent?)

From Dev

how JSONP will work in the behind-the-scenes in cross domain ajax calls

From Dev

How do I get a jQuery's $.getJson to work on a JSONP result?

From Dev

How to unit test functions with $http.jsonp in AngularJS?

From Dev

How come success function is never called in $http.jsonp (angularjs)

From Dev

How to unit test functions with $http.jsonp in AngularJS?

From Dev

Yii2 - JSONP response returns nothing (blank) and does not work, but JSON does

From Dev

Yii2 - JSONP response returns nothing (blank) and does not work, but JSON does

From Java

$http get parameters does not work

From Dev

.htaccess HTTP forcing does not work

From Dev

.htaccess HTTP forcing does not work

From Dev

node.js http module http.createServer how does it work?

From Dev

how does this fork() work

From Dev

How does a WebHook work?

From Dev

How does CocoaPods work

Related Related

HotTag

Archive