coding ceo

Can’t overcome same-origin-policy restriction for HTTP POST by XHR/JSONP

I’m writing this down with the above title, just to save time to many others who try to take advantage of jQuery excellent XHR API and try to submit a form (HTTP POST) across domains.

The button line – you can’t do a cross-domain XHR HTTP POST request.
When using the JSONP support of jQuery it it doesn’t fail, but simply translates the POST request into a GET.


$.post ('//, "callback=?");

Simply becomes identical to

$.get ('//', "callback=?");

What you should do is do a standard HTTP form submit into a hidden iframe.

I hope this post saved time to others, as I’ve just wasted 2 hours on that.
You can read more here:

This all came up while I was hacking a bit around – you should try it too.