透過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。
canadian pharmacy no prescription prescription drugs from canada online pharmacy non prescription drugs
https://medicationnoprescription.pro/# buying prescription drugs online canada
buying prescription drugs in india canadian pharmacy online no prescription needed buy drugs without prescription
http://medicationnoprescription.pro/# non prescription online pharmacy india
no prescription online pharmacies: mexico online pharmacy prescription drugs – buying prescription drugs online canada
http://edpill.top/# online ed drugs
buying prescription drugs from canada: online pharmacy prescription – canadian pharmacy no prescription
canada drugs no prescription online meds without prescription prescription drugs canada
international pharmacy no prescription: rx pharmacy no prescription – canadian pharmacy world coupon
https://medicationnoprescription.pro/# overseas online pharmacy-no prescription
https://medicationnoprescription.pro/# online no prescription pharmacy
cheapest ed medication: online ed medicine – buy ed pills
cheap ed drugs: cheap ed pills online – erectile dysfunction online prescription
http://medicationnoprescription.pro/# cheap drugs no prescription
offshore pharmacy no prescription canadian online pharmacy no prescription mail order pharmacy no prescription
buy medication online without prescription meds online without prescription medications online without prescription
prescription from canada: canada pharmacies online prescriptions – buying prescription drugs online from canada
best online pharmacy without prescription: non prescription canadian pharmacy – canada drugs without prescription
http://onlinepharmacyworld.shop/# canadian pharmacy world coupon code
http://onlinepharmacyworld.shop/# cheapest pharmacy to fill prescriptions with insurance
0old7b
buying prescription medicine online buy prescription drugs online without pharmacy no prescription
canadian pharmacy no prescription needed: canadian pharmacy world coupons – canadian online pharmacy no prescription
cheapest pharmacy for prescriptions: no prescription needed pharmacy – canadian pharmacy without prescription
http://edpill.top/# online erectile dysfunction medication
http://onlinepharmacyworld.shop/# prescription drugs online
http://onlinepharmacyworld.shop/# mail order pharmacy no prescription
http://medicationnoprescription.pro/# buy prescription drugs without a prescription
https://medicationnoprescription.pro/# canadian pharmacy online no prescription
non prescription canadian pharmacy: canada pharmacies online prescriptions – online medication no prescription