透過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。
zithromax cost australia: where can i get zithromax over the counter – zithromax antibiotic without prescription
doxycycline 100mg tablets: buy cheap doxycycline – where to get doxycycline
Отличный сайт! Тут Вы можете приобрестиВоздушные шары
https://gabapentinneurontin.pro/# neurontin canada online
average cost of prednisone: prednisone 40 mg daily – prednisone 5 mg tablet rx
how to get prednisone without a prescription buy prednisone 20mg prednisone 10 mg price
prednisone price canada: prednisone 10mg prices – prednisone online sale
zithromax for sale cheap can you buy zithromax over the counter buy zithromax without presc
Apresentando a melhor casa de apostas 1win
Recomendo uma excelente empresa de apostas 1win
http://prednisoned.online/# prednisone 500 mg tablet
buy cheap prednisone: prescription prednisone cost – buy prednisone 10 mg
http://doxycyclinea.online/# order doxycycline 100mg without prescription
amoxicillin 250 mg capsule: prescription for amoxicillin – cheap amoxicillin 500mg
cenforce remark – brand viagra online impressive
neurontin 150mg: neurontin mexico – neurontin india
order amoxicillin uk: cheap amoxicillin 500mg – amoxicillin 500 mg purchase without prescription
prednisone 10mg online: prednisone cream over the counter – prednisone for dogs
amoxicillin 500 mg purchase without prescription buying amoxicillin online amoxicillin 500mg cost
Escolha de uma casa de apostas confiavel 1win
Melhor site de apostas, recomendado 1win
amoxicillin online pharmacy: buy amoxicillin online cheap – prescription for amoxicillin
https://doxycyclinea.online/# doxycycline without prescription
prednisone 20mg nz: prednisone 20mg – prednisone prescription online
amoxicillin 500mg buy online uk amoxicillin price without insurance amoxicillin 500mg tablets price in india
prednisone price australia: prednisone 475 – prednisone pills for sale
zithromax cost canada generic zithromax 500mg india buy generic zithromax online
how to order doxycycline buy doxycycline without prescription online doxycycline
neurontin price australia: medicine neurontin – canada where to buy neurontin
http://gabapentinneurontin.pro/# neurontin cost in singapore