Pergunta

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. 
Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top