Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml ajax自动完成不工作_Xml_Ajax_Autocomplete - Fatal编程技术网

Xml ajax自动完成不工作

Xml ajax自动完成不工作,xml,ajax,autocomplete,Xml,Ajax,Autocomplete,我尝试了自动完成搜索 但是当我试图从服务器上运行脚本时,它不起作用。 我将源文件复制粘贴到宿主服务器中的新页面。有什么问题吗 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>jquery autocomplete xml search from beginning -

我尝试了自动完成搜索 但是当我试图从服务器上运行脚本时,它不起作用。 我将源文件复制粘贴到宿主服务器中的新页面。有什么问题吗

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>jquery autocomplete xml search from beginning - jsFiddle demo</title>

  <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.3.js'></script>



  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>


  <link rel="stylesheet" type="text/css" href="/css/result-light.css">


      <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/start/jquery-ui.css">



  <style type='text/css'>
    .red {color: red}
  </style>



<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
//for fiddle demo xml had to be loaded in this way
//use your own ajax call for your page
$.ajax({
    url: "/echo/xml/", //your url
    type: "POST", //may not need this-fiddle did-default is GET
    dataType: "xml", 
    data: {
        xml: "<geonames><geoname><name>London</name><geonameId>2643743</geonameId><countryCode>GB</countryCode><countryName>United Kingdom</countryName></geoname><geoname><name>London</name><geonameId>6058560</geonameId><countryCode>CA</countryCode><countryName>Canada</countryName></geoname><geoname><name>The Tower of London</name><geonameId>6286786</geonameId><countryCode>GB</countryCode><countryName>United Kingdom</countryName></geoname></geonames>"
    }, //should not need to define 'data' on your own xml call
    success: function(xmlResponse) {
        var data = $("geoname", xmlResponse).map(function() {
            return {
                value: $("name", this).text() + ", " + ($.trim($("countryName", this).text()) || "(unknown country)"),
                id: $("geonameId", this).text()
            };
        }).get();
        $("#test").autocomplete({
            source: function(req, response) {
                var re = $.ui.autocomplete.escapeRegex(req.term);
                var matcher = new RegExp("^" + re, "i");
                response($.grep(data, function(item) {
                    return matcher.test(item.value);
                }));
            },
            minLength: 2,
            select: function(event, ui) {
                $("p#result").html(ui.item ? ui.item.id : "Nothing selected, input was " + this.value);
            }
        });
    }
});
});//]]>  

</script>


</head>
<body>
  <h1>jQuery Autocomplete XML Source Search from Beginning</h2>
<p  class="ui-widget">Try typing 'Lo' it will match on 'London'. <br />Try typing 'don', no matches.<br />Try typing 'the', matches 'The Tower of London'. You get the idea.</p>

<div class="ui-widget">
    <label for="test">London matches: </label>
    <input id="test" />
</div>

<p id="result" class="ui-widget red"></p>


</body>


</html>

jquery从一开始就自动完成xml搜索-JSFIDLE演示
.red{color:red}
//  
jQuery从一开始就自动完成XML源搜索

尝试键入“Lo”,它将与“London”匹配
试着键入“don”,不匹配。
试着键入“the”,匹配“thetoweroflondon”。你明白了

伦敦比赛:


您复制的代码正在尝试(但失败)向服务器上的/echo/xml/发出请求。该URL是JSFIDLE的一个特殊特性。有关更多详细信息,请参阅。

是否有任何方法修改脚本以使其在宿主服务器上工作?