透過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。
canada pharmacies online prescriptions ed meds without doctor prescription canadian online pharmacies reviews
https://canadadrugs.pro/# cheap drugs online
canadian pharmacy for sildenafil pharmacies withour prescriptions canadian pharmacy prednisone
9640kl
http://canadadrugs.pro/# trusted canadian pharmacy
giant discount pharmacy: mexican pharmacy online reviews – canadian drug store
canadian pharmacy cheap: pharmacy drugstore online pharmacy – top online canadian pharmacies
https://canadadrugs.pro/# canada online pharmacy reviews
online pharmacies no prescription required pain medication: your discount pharmacy – best online canadian pharmacy
buy amoxiclav pill augmentin 375mg pills how to buy augmentin
rx online no prior prescription safe canadian internet pharmacies safe online pharmacies
https://canadadrugs.pro/# canadian pharmacy no rx
prescription drugs canadian: best canadian pharmacy – canada pharmacies
What’s up, after reading thuis remarkable aricle i amm ttoo delibhted
too shqre myy familiarity here with friends.
canadian pharcharmy online viagra: canadian online pharmacy no prescription – legitimate online pharmacy usa
vipps accredited online pharmacy list of online canadian pharmacies prescription drugs canada
http://canadadrugs.pro/# canadian pharmacy no prescrition
pharmacies not requiring a prescription: canada pharmacies online pharmacy – legitimate canadian internet pharmacies
canada drugs canadian pharmacy no presciption legitimate canadian pharmacies online
cheap viagra online canadian pharmacy: canadian pharmacy certified – canadian prescription costs
bestpharmacyonline.com canadian drugstore online canadian pharmacieswith no prescription
Отличный сайт! Рекомендую!1нейросеть текст
http://canadadrugs.pro/# reliable online drugstore
canadian pharmaceutical companies that ship to usa: canada pharmaceuticals online – overseas pharmacy
pain meds online without doctor prescription: prescription drugs online without – legal canadian prescription drugs online
https://canadadrugs.pro/# canadian pharmacy azithromycin
drugs canada: best 10 online pharmacies – canadian pharmacy no prescription
pharmacy drug store great canadian pharmacy mexican pharmacies shipping to usa
canadian pharmacy online ship to usa: high street discount pharmacy – online pharmacies in canada
http://canadadrugs.pro/# canadian neighbor pharmacy legit