Questions tagged [jsonp]

JSON with Padding (JSONP) is a technique for working around cross-domain Ajax limitations.

JSONP or "JSON with padding" is a communication technique used in JavaScript programs running in web browsers to request data from a server in a different domain, something prohibited by typical web browsers because of the same-origin policy. JSONP takes advantage of the fact that browsers do not enforce the same-origin policy on <script> tags.

To prevent cross-domain scripting, browsers normally block XMLHttpRequest (XHR) requests to other domains. JSONP works around this by wrapping or "padding" the JSON response such that it can be executed as a script.

For this reason, both the server and the client must support JSONP. The client adds a new <script> tag to the page, rather than creating an XHR, and typically informs the server what function name should be used for padding:

<script src="http://www.example.com/api/getdata?callback=response"></script>

The server then wraps the JSON response in a call to that function, which must be implemented by the client:

response({
    "example1": "somedata",
    "example2": "moredata"
});

Many client-side Ajax libraries abstract away the details of JSONP requests, allowing client code to treat them as normal JSON requests.

jQuery api example

$.ajax({
    url: 'http://www.example.com/api/getdata',
    jsonpCallback: 'jsonCallback',
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(json) {
       console.log(json);
    },
    error: function(e) {
       console.log(e);
    }
});

Security Note:

Be sure that you trust the server providing the JSONP response as this method allows the page to return a script that will be executed within the context of your page. Connecting to an untrusted service could give them access to your otherwise secure information.

References

4069 questions
1
vote
0 answers

JQuery JSONP ajax call to WCF triggers both error and callback function

This is really strange and I've tried to find the solution but havent been sucessfull, even after reading bunch of pages and tried out bunch of examples so here it is, even if this might be a duplicate question.
Edo
  • 78
  • 6
1
vote
0 answers

How can I wait for JSONP callback?

I am working on Flightstats api and I want to wait for callback from JSONP to pick up only "AA" flights for example from a certain date. Because Flightstats api allow to be requested only for one hour at one request, I have to make 24 requests at…
1
vote
2 answers

jsonp cross domain only working in IE

EDIT: At first I thought it wasn't working cross domain at all, now I realize it only works in IE I'm using jQuery to call a web service (ASP.NET .axmx), and trying to us jsonp so that I can call it across different sites. Right now it is…
iboeno
  • 3,809
  • 4
  • 20
  • 13
1
vote
0 answers

How to retrieve data contained in json format using API

please no negative points as I am so new. Plz check the jsFidle link and then read the following. Actually i am going to retrieve data using json, API and in the first dropdown list CAR MAKE have to be displayed. Then based on the selected CAR MAKE,…
1
vote
2 answers

Is it possible to access this (external) JSON data in my angularJS app?

The URL I wish to access is: http://steamcommunity.com/market/priceoverview/?country=US¤cy=2&appid=570&market_hash_name=Formed%20Alloy%20Set and I'm wondering if it's possible to parse this in AngularJS? I'm unfamiliar with JSONP so I don't…
Tito
  • 832
  • 10
  • 24
1
vote
0 answers

Jsonp not show the entry

Hi I've tried to parse a json with cross domain but it not work can someone help me? here the code
1
vote
0 answers

My JSONP call works in Chrome's Tampermonkey, but not Firefox's Greasemonkey

I wrote a userscript to call the API at Forvo.com and display the results on a third-party page, Memrise.com. Accessing Forvo's API requires a private key; I use it while testing, but I've erased it in the publicly-available code. The script works…
carpiediem
  • 1,918
  • 22
  • 41
1
vote
0 answers

Getting "The reference to entity must end with the ';' delimiter" error, but I can't use & or %26 in place of &

I'm developing a webpage which runs a script that calls a servlet, and the mode of data transfer is in JSONP. The script is something like this: $.ajax({ url :…
heisenbergman
  • 1,459
  • 4
  • 16
  • 33
1
vote
0 answers

JQuery get() results conversion

I am trying to get data from an outside domain that I do not have access to. My end goal is to be able to display it as a table, or later as a dynamic chart. The problem is that the domain that I am requesting information from only allows for either…
teknoliege
  • 11
  • 1
1
vote
1 answer

JSONP - Callback was not called

I created a jsonp ajax call for getting data via cross domain. The thing right now is - I successfully manipulated it to send data over a webserver. But it fails receiving data in a get call. When I have look in the debugger I see that the network…
abc
  • 31
  • 4
1
vote
1 answer

JSONP not working for cross domain AJAX

I've look at all the cross-domain ajax questions, and still cannot figure out what is wrong with my JSONP request. All I am trying to do is get the contents of an external page, cross domain using JSONP. Unfortunately, firefox still gives…
wayofthefuture
  • 8,339
  • 7
  • 36
  • 53
1
vote
3 answers

Jquery/JavaScript - Store Ajax jSONP response into variables

I'm getting the result of an ajax request using JSONP without any issues. Here is my code function TestJSONP() { $.ajax({ url:…
Kushan Randima
  • 2,174
  • 5
  • 31
  • 58
1
vote
1 answer

Creating a JSONP Callback From Safari Extension

I'm trying to load some data from Reddit via a Safari extension. I'm using a JSONP pattern to create the callback function and attach the new src to the script. However, it looks like there are two window namespaces, and the function that I…
4m1r
  • 12,234
  • 9
  • 46
  • 58
1
vote
1 answer

How do I actually setup SSO with Vanilla jsconnect?

I have a site with a basic members auth system built into it, I wanted to allow the logins for this site to also work on a vanilla forum using the jsconnect plugin. The forum is built within a folder of the site. I've been through the documentation…
Jai
  • 2,096
  • 5
  • 25
  • 37
1
vote
2 answers

Handling a nested array in Flask request

I built a webserver in Flask and I'm passing in the request using jsonp. One of the things I pass in is an nested array and when I retrieve the data in Flask, the array is completely messed up. Here's my code index.html var array =…
user1998511
  • 455
  • 1
  • 8
  • 21
1 2 3
99
100