As mentioned above, Cross Browser security restrictions limit your alternatives
There are four alternatives that I know to get around this. JsonP is probably the most flexible, but I have included them all for completeness.
1) iframe is the simplest, but your widget will have limited access to the website that contains it, and vice versa.
2) Jsonp = the most flexible - this works with a tag. Your serveride code takes a callback parameter and puts it in front of any json passed to it.
Php example
<?php header("content-type: application/json"); $json = array('example'=>'results'); // Wrap and write a JSON-formatted object with a function call, using the supplied value of parm 'callback' in the URL: echo $_GET['callback']. '('. json_encode($json) . ')'; ?>
And the jQuery code will look like this:
$.ajax({ url:'http://yourserver.com/ajax.php', dataType:'jsonp', success: function(data) { alert(data); } });
The user of your widget can either copy the insert or the javascript that they need, or even better, load it directly from your web server using a script src call.
3) DNS alias. Require all users of your widget to record in their DNS to your server so that it is in the same top-level domain. IE point - widgetprovider.consumersdomain.com to your server. (You will need a fixed ip as setting up a virtual host for all domains that will be unpleasant). Then you can download javascript with the script tag as described above, but you donβt need to worry about jsonp and you can use standard ajax calls to interact with the site.
4) Flash, Silverlight - can cross the cross-domain policy, including the xml file on your server.
Bonus - I think you can do it with WebSockets after these roles are real.