jQuery autocomplete - xml cross site request

亡梦爱人 提交于 2019-12-02 06:32:54

问题


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



来源:https://stackoverflow.com/questions/5916682/jquery-autocomplete-xml-cross-site-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!