透過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。
purchase amoxicillin online: amoxicillin online purchase – amoxicillin 500
https://amoxila.pro/# buy amoxicillin online uk
where to buy zithromax in canada: how to buy zithromax online – zithromax prescription online
Passando para a melhor casa de apostas 1win
Melhor site de apostas 1win
where can i buy zithromax medicine: buy zithromax online fast shipping – zithromax generic cost
neurontin 100mg tablet neurontin 300mg tablet cost neurontin 600 mg price
https://prednisoned.online/# can you buy prednisone over the counter in canada
buy doxycycline online without prescription: doxy 200 – order doxycycline online
order doxycycline online: doxycycline order online – buy doxycycline
where to buy amoxicillin: amoxicillin 250 mg – amoxicillin 800 mg price
http://doxycyclinea.online/# how to buy doxycycline online
doxycycline 500mg doxycycline tetracycline price of doxycycline
neurontin 50mg tablets: canada where to buy neurontin – neurontin prescription medication
30mg prednisone: can i buy prednisone online without a prescription – prednisone cost us
prednisone without a prescription buy prednisone mexico prednisone 12 mg
prednisone 20 mg prices prednisone online 1 mg prednisone daily
zithromax online australia: order zithromax without prescription – where to get zithromax
https://zithromaxa.store/# buy zithromax online australia
neurontin medicine: neurontin capsules 600mg – neurontin prescription medication
https://amoxila.pro/# can you purchase amoxicillin online
Отличный сайт! Тут Вы можете найтиновые сервера майнкрафт
zithromax 250 mg zithromax 500 mg for sale zithromax online no prescription
Купить диплом быстро и качественно
купить диплом специалиста diplom-msk.ru .
amoxicillin buy canada: rexall pharmacy amoxicillin 500mg – where can i buy amoxicillin over the counter uk
amoxicillin medicine over the counter: where can i get amoxicillin 500 mg – amoxicillin 500mg pill
http://doxycyclinea.online/# buy cheap doxycycline
by prednisone w not prescription: prednisone cost canada – prednisone 2.5 tablet
where can i buy amoxicillin over the counter uk amoxicillin brand name cost of amoxicillin
prednisone 20mg prednisone canada prices medicine prednisone 5mg