Crushing
Crushing

Reputation: 447

Javascript cross domain POST/GET

I want to call web services from my javascript. I've read a bunch of the posts on here such as

Simplest SOAP example

But the example post to webservicex.net returns null (xmlhttp.responseXML in firebug). Where i get confused is that all these libs/proxies/apps/etc talk about communicating with a web service but I don't see js or it appears everything is done in the backend.

I want to call a web service and have everything returned to js, the way that seems most rational is the use a proxy server to make the request so the browser doesn't complain.

I'm new to the web server world, Apache mod_proxy and/or a proxy server are pretty ambiguous to me, The docs said what they did but not implement.. Can someone provide some links to put me in the right direction with some examples or tutorials?

Thanks

Upvotes: 3

Views: 2094

Answers (4)

Justin wong
Justin wong

Reputation: 638

jsonp only support get, so I can not submitted data, the best way is to implement a cross-domain proxy in you the same domain. Reference here : http://www.codeproject.com/Articles/25218/Fast-Scalable-Streaming-AJAX-Proxy-continuously-de

Upvotes: 0

Im0rtality
Im0rtality

Reputation: 3533

You can write simple PHP (or anything you prefer) script which takes URL and POST/GET params, feeds them to remote server and prints out result for your javascript.

So, you can call non-remote script to retrieve remote content.

Upvotes: 1

John Michel
John Michel

Reputation: 86

If at all possible, you might want to try and use JSONP to do cross-domain AJAX requests. A quick breakdown of how it compares to normal JSON requests can be found here.

Upvotes: 1

vbence
vbence

Reputation: 20333

Depending on the API, it is possible to dynamically insert a <script> tag into your document like:

<script src="http://www.otherdomain.com/list.php?category=23&order=2"></script>

Then the script can send back the results in a JS like:

yourCallback([{'Stool', 12000}, {'Table', 4000}]);

And of course the yourCallback() function you have written will populate the HTML document with the results.

Of course it depends on the API you are using. If it is apublic API, it's interface is documented and this stuff is hidden. If it is not a public API, you probably are not OK legally to access their services from a third-party site.

Upvotes: 1

Related Questions