Skip to content Skip to sidebar Skip to footer

Prototype Plugin For Cross-domain-request? (to Other Host's Websites!)

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-protot

Solution 1:

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:

<scriptsrc="//ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script><scriptsrc="//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)

Post a Comment for "Prototype Plugin For Cross-domain-request? (to Other Host's Websites!)"