透過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。
non prescription prednisone 20mg: prednisone 10 mg – prednisone 30 mg tablet
10 mg prednisone: how to buy prednisone – prednisone for sale online
https://amoxil.icu/# cost of amoxicillin prescription
http://amoxil.icu/# amoxicillin 500mg price in canada
compare prednisone prices: prednisone without prescription.net – prednisone for cheap
http://amoxil.icu/# amoxicillin 500 mg cost
get clomid now: order generic clomid no prescription – cost cheap clomid online
http://ciprofloxacin.life/# ciprofloxacin 500 mg tablet price
prednisone capsules: can you buy prednisone over the counter uk – prednisone 10 mg
order cheap clomid no prescription: can i purchase generic clomid tablets – where to buy generic clomid without insurance
Heyya terrificc website! Doess runing a log similar too thjs takke
a massive amount work? I’ve absolutly noo understanding of
coding howewver I waas hopig to start my ownn blog in thee near future.
Anyway, shold yoou have aany ideas or tips forr nnew blog
owners pleaae share. I knw thius iss off subject howevsr I simjply wanted too
ask. Many thanks!
where can i buy generic clomid without prescription: where can i buy generic clomid without insurance – can i buy clomid without prescription
https://ciprofloxacin.life/# cipro ciprofloxacin
where to buy clomid no prescription: where can i get clomid now – how can i get generic clomid price
can i order clomid: where to get clomid without rx – can i purchase cheap clomid
http://ciprofloxacin.life/# ciprofloxacin 500 mg tablet price
http://ciprofloxacin.life/# buy generic ciprofloxacin
https://amoxil.icu/# cost of amoxicillin prescription
cost cheap clomid pills: how to buy clomid without rx – clomid rx
http://amoxil.icu/# amoxil pharmacy
buy cheap clomid no prescription: where to buy generic clomid no prescription – where can i buy clomid
http://ciprofloxacin.life/# cipro 500mg best prices
https://ciprofloxacin.life/# buy cipro cheap
can you get generic clomid pills: can you buy generic clomid no prescription – how to get generic clomid without insurance
how to buy clomid no prescription: cost generic clomid pills – how can i get generic clomid online
https://ciprofloxacin.life/# ciprofloxacin order online
http://amoxil.icu/# amoxicillin without a prescription
http://ciprofloxacin.life/# ciprofloxacin generic
prednisone 200 mg tablets: order prednisone online canada – prednisone 54899
https://ciprofloxacin.life/# ciprofloxacin generic price