Question

A page served from one.com has the following code:

  $.post 'http://two.com/',
    data: 'example'
  , dataType: 'jsonp'

It gives the following console error:

XMLHttpRequest cannot load http://two.com. Origin http://one.com is not allowed by Access-Control-Allow-Origin. 
Was it helpful?

Solution

JSONP is, by its very nature, a GET, not a POST. It uses a script tag as its transport mechanism, and script tags GET their scripts.

$.get 'http://two.com/',
  data: 'example'
, dataType: 'jsonp'

Also note that the server has to support JSONP for it to work, just like it would have to support (say) XML if you were requesting that. The format of what it sends back is specific to JSONP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top