开发者

Javascript cross domain POST/GET

开发者 https://www.devze.com 2023-02-21 00:29 出处:网络
I want to call web services from my javascript.I\'ve read a bunch of the posts on here such as Simplest SOAP exa开发者_开发百科mple

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

Simplest SOAP exa开发者_开发百科mple

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


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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号