Are there any plugins or best-practices for ajax cross-domain-querys?
I found only this one: http://www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/ but i开发者_Python百科t didn't work for me...
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?
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
}
See DEMO (works with Prototype 1.7 and jQuery 1.5)
精彩评论