jQuery autocomplete - xml cross site request

2019-02-26 21:24发布

问题:

The XML feed for my autocomplete is on another server. Is there a client side (javascript) method of getting this XML document?

I know I can create a proxy with php, jsp, etc.. but I need to do it all client side. This is how I call the file now that only works if it is on the same domain:

function callAjax(url) {
  $.ajax({
        url : url,
        dataType : "xml",
        success : function(xmlResponse) {
              totalrec = $("TOTALREC", xmlResponse).text();
            $.merge(data1, $("ROW", xmlResponse).map(returnResults).get());
        }// end of success
  });

回答1:

You could do it using JSONP

  dataType: 'jsonp'

Here you have living demo:

http://jqueryui.com/demos/autocomplete/#remote-jsonp

This doesn't do it with xml, but json. But shouldn't be hard to change it.

hope this helps. Cheers



回答2:

YQL might be able to do what you want. It allows you to do cross-domain requests.

Have a look at this: Cross-domain requests with jQuery

H.T.H