2013-10-02 29 views
-1

我從小提琴的阿賈克斯呼叫如下。如何修改ajax調用以在我的託管服務器上運行?修改小提琴的阿賈克斯呼叫

<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> 

請給上面的代碼部分修改的樣本

+0

如何您的代碼不知道您的要求修改,請與代碼一起指定需要到目前爲止你試過 – SarathSprakash

+0

我的要求是修改上面的ajax調用代碼在我的託管服務器上工作。這是你不明白是什麼問題.. – user2822230

+0

可能你應該表現出一些尊敬的同胞成員好吧。這裏的人都是志願者,他們幫助人們解決他們的疑惑,而不是對一些複製的代碼進行修改。 – SarathSprakash

回答

0

試試這個

<script type='text/javascript'> 
$(window).load(function(){ 
//for fiddle demo xml had to be loaded in this way 
//use your own ajax call for your page 
$.ajax({ 
    url: "your.xml", //change with your xml url 
    type: "POST", //may not need this-fiddle did-default is GET 
    dataType: "xml", 

    success: function(xmlResponse) { 
     var data = $("geoname", xmlResponse).map(function() { 
      return { 
       value: $("name", this).text() + ", " + ($.trim($("countryName", this).text()) || "(unknown country)"), 
       id: $("geonameId", this).text() 
      }; 
..........