tags:

views:

37

answers:

2

Hi,

I want to post some data via javascript to another domain. Something like:

http://www.othersite.com/submitfunnyname?name=blah

The other site (othersite.com) has a REST interface that you can call (well actually this is a get example) to submit a funny name to them.

Can I do this already with javascript? I'm a little confused on this - I know if that service wants to return some data, I'd need to use something like JSON-P - even though here I'm submitting some data, I guess the service will return some message structure letting me know the result, so it would have to be JSON-P, right?

Thanks

+1  A: 

You can either use JSON-P if the site supports it, or you can use your web server as a proxy - by making requests to your server, which will in turn use a library such as cURL to make the actual request to the remote site.

Justin Ethier
+1  A: 

Not a particular expert in JavaScript, but isn't this an example of "cross-site scripting", which is not allowed due to possible security threats?

I believe you need to have all HTTP calls being made to the same server domain as the page. You could have a handler on your own site pass the information on to the othersite.com.

mbmcavoy
This is pretty much correct, it's the [same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy) kicking in, instituted to mitigate XSS attacks.
Nick Craver
Yeah but if the other site supports JSON-P, it's a way around the XSS limitations (if my terminology is right here).