How do jQuery do its cross-domain ajax calls and how can I replicate em with mootools

谁说我不能喝 提交于 2019-11-28 09:31:00

It's said right on the page that it's JSONP.

JSONP is a trick where the server, instead of returning the usual response, wraps it into a method call of the user-supplied method, e.g. instead of:

{"foo": "bar", "baz":"bah"}

It would return:

temporaryCallbackFunctionName({"foo": "bar", "baz":"bah"});

jQuery defines the temporary callback function and inserts a <script src="..."></script> element, which is not limited by the same origin policy.

When the script is loaded, the function is executed and that's it.

The downside is that if the server is evil (or hacked) it can now execute arbitrary code in your browser.

More info here.

moff

You may use JSONP in MooTools by using a plugin, JSONP. It's made by Aaron Newton, one of the core MooTools developers.

This is included in MooTools more since v1.2.2 (released on April 23rd 2009).

Check this documentation page for more info.

It seems you can't do it with Mootools, according to its API docs and this forum.

The reason this is limited is probably because of Cross-site scripting attacks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!