透過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。
can i buy clomid for sale: can i order generic clomid without insurance – can i buy clomid
prednisone 20mg cheap: prednisone tablets india – prednisone 20 mg generic
https://ciprofloxacin.life/# buy ciprofloxacin
http://amoxil.icu/# amoxil pharmacy
https://ciprofloxacin.life/# buy ciprofloxacin
order cheap clomid can you buy generic clomid – can you buy generic clomid tablets
https://amoxil.icu/# amoxicillin 500
how can i get cheap clomid for sale can i order cheap clomid for sale – cost cheap clomid price
can you buy cheap clomid now get clomid online – where to buy cheap clomid without rx
can i buy clomid without prescription clomid – how to get cheap clomid pills
where to buy clomid without a prescription cost of cheap clomid no prescription – can i purchase cheap clomid without insurance
how to buy clomid no prescription cost clomid without a prescription – can you get clomid without a prescription
https://amoxil.icu/# cost of amoxicillin prescription
clomid cheap: cost clomid no prescription – can i buy clomid no prescription
cheap generic prednisone: prednisone pak – canada buy prednisone online
can i purchase generic clomid pill get cheap clomid without dr prescription – buy generic clomid prices
http://amoxil.icu/# amoxicillin without rx
https://amoxil.icu/# amoxicillin 500mg no prescription
https://amoxil.icu/# buying amoxicillin in mexico
http://amoxil.icu/# amoxicillin online canada
how to get cheap clomid pills buying clomid tablets – cost clomid without a prescription
https://amoxil.icu/# amoxicillin 500mg no prescription
https://amoxil.icu/# buy amoxicillin
buy generic clomid cost of cheap clomid tablets – how to buy cheap clomid without prescription
can i buy generic clomid without prescription: where to get clomid no prescription – where can i get generic clomid without a prescription
prednisone 30 mg: prednisone no rx – how can i order prednisone
https://amoxil.icu/# prescription for amoxicillin
https://amoxil.icu/# amoxicillin 500mg price in canada
how can i get generic clomid without insurance where buy clomid no prescription – can i purchase generic clomid pills
where can i buy clomid for sale can i purchase cheap clomid without a prescription – cost of clomid without prescription