Asked  6 Months ago    Answers:  5   Viewed   29 times

Is it possible to post data to JsonP? Or does all data have to be passed in the querystring as a GET request?

I have alot of data that I need to send to the service, cross domain, and it is too large to send via the querystring

What are the options for getting around this?



It is not possible to do an asynchronous POST to a service on another domain, due to the (quite sensible) limitation of the same origin policy. JSON-P only works because you're allowed to insert <script> tags into the DOM, and they can point anywhere.

You can, of course, make a page on another domain the action of a regular form POST.

Edit: There are some interesting hacks out there if you're willing to go to a lot of effort inserting hidden <iframe>s and mucking about with their properties.

Tuesday, June 1, 2021
answered 6 Months ago

JSONP is not JSON. A JSONP response would consist of a JavaScript script containing only a function call (to a pre-defined function) with one argument (which is a JavaScript object literal conforming to JSON syntax).

The response you are getting is JSON, not JSONP so your efforts to handle it as JSONP fail.

Change dataType: 'jsonp' to dataType: 'json' (or remove the line entirely, the server issues the correct content-type so you don't need to override it).

Since your script is running on a different origin to the JSON then you will also need to take steps (most, but not all, of which require that you control the host serving the JSON) to work around the same origin policy.

Wednesday, June 9, 2021
answered 6 Months ago

you can use getJSON for example

$.getJSON('ajax/test.json', function(data) {
  $('.result').html('<p>' + + '</p>'
    + '<p>' + data.baz[1] + '</p>');

check complete getJSON documentation


I was wrong... using Jquery.ajax will cause cross-browser issue but not with Jquery.getJSON

Here is an example of cross-domain get JSON


Firefox has a problem with HTTPS, as i know it will be fixed if you send your request like this

$.getJSON('ajax/test.json',{}, function(data) {
  $('.result').html('<p>' + + '</p>'
    + '<p>' + data.baz[1] + '</p>');

Source: AJAX https POST requests using jquery fail in Firefox

Hope this helps

Saturday, October 9, 2021
answered 2 Months ago

This is a little trickier than normal since it's a Django website, and we need to deal with Django's Cross-site Request Forgery protection by generating a CSRF token.

Here's how to do it with httr, using the example file provided here:

csrf <- GET(url='')$cookies$csrftoken
res <- POST(url='', 
out <- read.delim(file=textConnection(content(res)), 

The GET call generates the CSRF token, which is needed for the subsequent POST call.

Thursday, October 28, 2021
answered 1 Month ago

I found the problem.

My post code uses $.ajax(...), as shown in initial message.

But jquery's .ajax post data as application/x-www-form-urlencoded. This worked in previous versions of WebAPI, but in latest update it seems it doesn't accept application/x-www-form-urlencoded by default.

I changed content type to application/json, and I had to convert data to json, and this solved the problem.

So, instead of

    type: "POST",
    url: uri,
    data: dataObj,
    success: function(...)

I had to change to

    type: "POST",
    url: uri,
    data: JSON.stringify(dataObj),
    contentType: "application/json; charset=utf-8",
    success: function(...)
Tuesday, November 2, 2021
Anton Barinov
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :