2

I need to submit a webform to a online service which returns a HTTP 200 if everything went well and something different if the form was submitted incorrectly. Using AJAX is what I want to make pretty errors appear to inform my users that they have sent messy information.

So I started to do what I have done previosly, which are mentioned in this question but as the form is submitted to another domain besides my own (cross-domain), it didn't take long to find out that Firefox sent OPTIONS request instead of the POST I expected.

With those options being unavailable, I searched further and found out about the JSONP function, which I found out not supporting POST for cross-domains requests.

Clearly, my head is about to implode after this. Have I missed something?

Community
  • 1
  • 1
Industrial
  • 41,400
  • 69
  • 194
  • 289
  • possible duplicate of [How do I send a cross-domain POST request via JavaScript?](http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript) – Piskvor left the building Nov 24 '10 at 22:51

1 Answers1

2

You might want to look at window.postMessage in html5. There's even a jQuery plugin called jQuery postMessage which tries to bring support to older browsers (through hidden iFrames) which don't support it yet.

Generally though, posting to a separate domain isn't supported via ajax. Another (possibly easier) alternative is to simply create a proxy script on your own server that takes the ajax data and does a POST via curl to your external service and simply returns the result code back to your own ajax call. It doesn't suffer the cross domain restriction since you're posting to your own domain.

markquezada
  • 8,444
  • 6
  • 45
  • 52