Search code examples
javascriptautocompletesame-origin-policy

How to tackle same origin policy in Mozilla


I am implementing YUI autocomplete in my project. I have created a web service which provides autocomplete suggestions. All things are working fine when I deploy my application and web service on same machine. But when I deploy the web service on different machine then it do not work in Firefox (But it do work in IE). I think because of same origin policy its not working in Mozilla.
Here is my autocomplete code

<script type="text/javascript">
YAHOO.example.BasicRemote = function() {

    // Using an XHRDataSource to connect to web service
   var oDS = new YAHOO.util.XHRDataSource("http://host_other_than_my_machine/i2b2/services/AutocompleteService/getCodes"); 


    // Set the responseType as XML
    oDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;

    // Define the schema of the delimited results
    oDS.responseSchema = { 
                            resultNode: 'code', 
                            fields: ['value']             
                         }; 

    // Enable caching
    oDS.maxCacheEntries = 0;

    // Instantiate the AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);

    return {
        oDS: oDS,
        oAC: oAC
    };
}();
</script>   

My questions are
1) Is same origin policy is actual problem ? If yes then Is IE not bound to same policy as my code is working in IE ?
2) How to get rid of it ? I know some php code can be used to redirect request but how I can use it here ?

~Ajinkya.


Solution

  • Used PHP proxy provided by Yahoo and redirected all requests to it. http://developer.yahoo.com/javascript/howto-proxy.html