2

I just found out (the hard way) that you can't make ajax calls to another domain.

I've read about iFrames (which only works in IE6) and a cross domain xml request (which only works from ie8 onwards)

So is there any other way? I basically just need to send data to another server, not receive it.

4 Answers 4

2

sounds like you would need to use a server-side proxy script. i.e. an AJAX request to a (for example) PHP script which would make an HTTP/cURL request for you.

Sign up to request clarification or add additional context in comments.

Comments

0

JSONP might be what you need. there are plenty of examples out there. Here's a good one: http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

Comments

0

I should have clarified: I did not want to use a (large) library, and can't use a proxy-script.

Basically I decided a GET would be "good enough" for what I was trying to do (track impressions)

So when the script gets triggered it creates an iframe, hides it and sets the source url to my script + the correct GET parameters. No forms needed.

1 Comment

Then you could just as well use add an Image to the dom and remove it on onload... The problem with this is that you cannot really check if the request was successful or not, but if this might not be important.
0

I'd combine <iframe> and the <form>'s ability to be sent even to another domain. Main file:

<iframe id=ifr src=form.html style="display: none;"></iframe> <input id=send-me><input type=button onclick="senddata();" value=Send> <script> function senddata() { var ifr = document.getElementById('ifr'), f = ifr.contentWindow.document.forms[0]; f.elements.data.value = document.getElementById('send-me').value; f.submit(); } </script> 

form.html:

<form action="http://another.doma.in/" method=post> <input type=hidden name=data> </form> 

This will make POST HTTP request to another domain and send there the content of <input id=send-me>.

Please note that this is just basic proposal and will need adjustment if you want to for example send data multiple times without refresh.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.