开发者

sending data to another website and receive result

If i have a website1.com and website2.com, can I send data ( ex: value from input ) from website2.com to website1.com and receive result? with no page refresh or redirect. I'd like to use only javascript & ajax, no PHP or jQuery. If it is possible give me an example how to do it.

I thought about creating an script element ( with javascript) on website2.com with src like : website1.com?data=<value from input>, and when script el开发者_运维百科ement loads the src, it will show me an result, but maybe there is a better option to do this.

PS: I will have more separated datas to send.

Note: this is not XSS, just a public project for websites, which will need to update datas every x minutes and to send some data to website1.

Thanks.


Your question is not completely clear, but in general when you have to do cross-site AJAX you have to use JSONP


Since XmlHttpRequest does not work cross-domain, you have to use JSONP. Basically, this is adding a script tag dynamically as you're suggesting to do. Then, the server uses your GET datas, does whatever it wants, and usually "prints" a callback function.

When you call a file using the script tag, it will evaluate everything displayed. This is why, if, on the server side, you're doing :

<?php
echo 'alert(1);';
?>

This will be evaluated as javascript. You can then easily understand how to use a callback function (another GET parameter).

Also, in jQuery, there is an option called 'jsonp' when you call $.ajax (using "callback" as default GET parameter, but can be changed).


You could have some XSS issues but it is possible you could use ajaxgold. It is an pretty easy manner to send pretty much everything over.

Call send to website2

postDataReturnText( 'http://website2.com', 'data=bla', getResult );

Return the result

function getResult( text ) {}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜