透過JS跨網域存取XML檔
為了一些安全性的因素,通常伺服器會阻擋跨網域的XML存取,當然如果你是該網站開發者,所開發的頁面應該將會被放在被認可的網域中,不會碰到這個問題,但我們在開發前期有可能會不在所屬的網域,這樣就會造成開發上的困難,不過我們可以透過Yahoo所提供的YQL查詢語法來解決這個問題,以下就是相關的說明:
若我們在自己的電腦用以下的語法去存取一個網路上的XML
<script> $(function () { var xmlSource = "http://stanley.cloudlab.tw/crossDomainXML/testXML.xml"; $.ajax({ url: xmlSource, success: function (data) { console.log(data); } }) }) </script>
很可能會出現「No Access Control Allow Origin」的訊息:
但如果套用上YQL之後
<script> $(function(){ var xmlSource = "http://stanley.cloudlab.tw/crossDomainXML/testXML.xml"; var yqlURL = [ "http://query.yahooapis.com/v1/public/yql", "?q=" + encodeURIComponent("select * from xml where url='" + xmlSource + "'"), "&format=xml&callback=?" ].join(""); $.getJSON(yqlURL, function(data){ console.log(data) }); }) </script>
可以看到已經可以抓到XML內容,這樣可以讓我們較為方便的去開發,其他詳細的使用說明可以參考Yahoo YQL Guide。
п»їbest mexican online pharmacies Certified Pharmacy from Mexico mexican rx online mexicanpharm.shop
order albuterol inhaler purchase albuterol generic order antihistamine pills
http://canadianpharm.store/# canadian pharmacy 1 internet online drugstore canadianpharm.store
mexican pharmacy: Online Mexican pharmacy – mexican pharmacy mexicanpharm.shop
mail order pharmacy india buy medicines online in india indianpharmacy com indianpharm.store
purple pharmacy mexico price list: mexican online pharmacies prescription drugs – medication from mexico pharmacy mexicanpharm.shop
http://mexicanpharm.shop/# buying prescription drugs in mexico online mexicanpharm.shop
reputable indian online pharmacy Indian pharmacy to USA indian pharmacy online indianpharm.store
indian pharmacy online: india pharmacy – cheapest online pharmacy india indianpharm.store
canada drugs online: Canada Pharmacy online – canadian pharmacy antibiotics canadianpharm.store
pharmacy wholesalers canada Licensed Online Pharmacy canadian pharmacy reviews canadianpharm.store
http://indianpharm.store/# mail order pharmacy india indianpharm.store
purple pharmacy mexico price list: Online Pharmacies in Mexico – mexico pharmacies prescription drugs mexicanpharm.shop
http://canadianpharm.store/# the canadian pharmacy canadianpharm.store
canadian pharmacy drugs online: Canada Pharmacy online – canadian pharmacy near me canadianpharm.store
http://mexicanpharm.shop/# mexico drug stores pharmacies mexicanpharm.shop
indian pharmacy online international medicine delivery from india online shopping pharmacy india indianpharm.store
https://mexicanpharm.shop/# mexico drug stores pharmacies mexicanpharm.shop
https://mexicanpharm.shop/# mexico drug stores pharmacies mexicanpharm.shop
mexico drug stores pharmacies: Online Mexican pharmacy – mexican pharmacy mexicanpharm.shop
canadian neighbor pharmacy Canadian Pharmacy thecanadianpharmacy canadianpharm.store
https://indianpharm.store/# top 10 online pharmacy in india indianpharm.store
my canadian pharmacy review: Canadian Pharmacy – canadian pharmacy 365 canadianpharm.store
mexican mail order pharmacies: Online Pharmacies in Mexico – mexican pharmaceuticals online mexicanpharm.shop
pharmacy website india: order medicine from india to usa – mail order pharmacy india indianpharm.store
pharmacies in mexico that ship to usa: Online Pharmacies in Mexico – pharmacies in mexico that ship to usa mexicanpharm.shop
top 10 online pharmacy in india order medicine from india to usa reputable indian online pharmacy indianpharm.store
http://mexicanpharm.shop/# mexican pharmacy mexicanpharm.shop
best online pharmacy india Indian pharmacy to USA buy prescription drugs from india indianpharm.store
mexico pharmacies prescription drugs: Online Pharmacies in Mexico – best online pharmacies in mexico mexicanpharm.shop