跨域请求的原型插件?(到其他主机的网站!) [英] prototype plugin for cross-domain-request? (to other host's websites!)

查看:35
本文介绍了跨域请求的原型插件?(到其他主机的网站!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有适用于 ajax 跨域查询的插件或最佳实践?

Are there any plugins or best-practices for ajax cross-domain-querys?

我只找到了这个:http://www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/ 但它对我不起作用......

I found only this one: http://www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/ but it didn't work for me...

我首先用原型 1.7 尝试过,切换到 1.5 后它起作用了……但为什么 1.7 不再支持它了?!知道如何在 1.7 中工作吗?

edit: I tried it first with prototype 1.7, after switch to 1.5 it worked... But why isn't it supported anymore in 1.7?! Any idea's how to get work in 1.7?

推荐答案

如果你没有找到原生的 Prototype 解决方案,那么你可以尝试使用 jQuery 仅用于 AJAX 和 Prototype 用于其他一切.它只有 29kB,您可以从 Google 热链接(或其他 CDN 选择).只需在 HTML 中包含 Prototype 和 jQuery 并记住调用 jQuery.noConflict() 否则 jQuery 将使用 Prototype 也使用的 $() 函数:

If you don't find a native Prototype solution then you can try using jQuery just for AJAX and Prototype for everything else. It's only 29kB and you can hot-link from Google (or other CDNs to choose). Just include both Prototype and jQuery in your HTML and remember to call jQuery.noConflict() because otherwise jQuery would use the $() function which Prototype also uses:

<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
    jQuery.noConflict();
</script>

现在您可以在脚本中使用它们,如下所示:

And now you can use both of them in your script with something like this:

// using jQuery:
jQuery.ajax({
    url: 'http://...',
    type: 'POST',
    dataType: 'jsonp',
    data: {
        // ...
    },
    success: yourHandler
});

// using Prototype:
function yourHandler(data) {
    // use returned data
}

参见 DEMO(适用于 Prototype 1.7 和 jQuery 1.5)

See DEMO (works with Prototype 1.7 and jQuery 1.5)

这篇关于跨域请求的原型插件?(到其他主机的网站!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆