透過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。
Отличный сайт! Всем рекомендую!slivkursov.net
A domain name name, or Web address, is an deal with where it is easy to be observed online. It’s how you’ll communicate yourself by means of email or your site and it’s which buyers assume of once attempting to discover you.
Feel free to visit my web-site – Watch Free Poker TV Shows
Ретрит http://ретриты.рф международное обозначение времяпрепровождения, посвящённого духовной практике. Ретриты бывают уединённые и коллективные; на коллективных чаще всего проводится обучение практике медитации.
My webpage Daycare Near Me
top 10 online pharmacy in india: indianpharmacy com – buy medicines online in india
mexican online pharmacies prescription drugs medication from mexico pharmacy mexican online pharmacies prescription drugs
mexican mail order pharmacies: buying prescription drugs in mexico online – buying prescription drugs in mexico online
best india pharmacy: top 10 pharmacies in india – п»їlegitimate online pharmacies india
Отличный сайт! Всем рекомендую!картина на холсте в Тюмени
Discover the world of excitement at Pin Up Casino, the world’s leading online casino. The official website Slot pick up offers more than 4,000 slot machines. Play online for real money or for free using the working link today
buy voveran pills – buy isosorbide 40mg online cheap buy generic nimodipine for sale
промокоды на 1хбет при первой регистрации. Utilisez – le lors de votre inscription pour obtenir un bonus de 100% jusqu’a 130$. Pour obtenir des bonus du bookmaker 1xbet, vous devez remplir certaines conditions, mais les codes promotionnels vous permettent de les obtenir beaucoup plus facilement. La taille des bonus disponibles pour les joueurs via les codes promotionnels 1xBet peut etre petite, mais meme un petit bonus peut augmenter considerablement le potentiel de jeu du client.
Here is my webpage … Daycares popular listings
http://indianpharmacy.company/# top 10 online pharmacy in india
online pharmacy generic finasteride: percocet overseas pharmacy – xalatan online pharmacy
It’s genuinely very complex in this busy life to listen news on Television, therefore I simply use internet for
that reason, and take the newest information.
Here is my web-site; ปอยเปต คาสิโน ออนไลน์
mail order pharmacy india: indian pharmacy online – Online medicine home delivery
mexico pharmacies prescription drugs: buying prescription drugs in mexico – buying prescription drugs in mexico online
buying from online mexican pharmacy: mexican mail order pharmacies – mexican rx online
mexican drugstore online medicine in mexico pharmacies reputable mexican pharmacies online
I seriously love your site.. Pleasant colors & theme. Did you develop this amazing site yourself? Please reply back as I’m wanting to create my very own blog and would love to find out where you got this from or just what the theme is named. Appreciate it.
watch ig anon-inst.com .
Pin up casino official Slot pick up casino website – login and play online
вывод из запоя цены санкт-петербург http://vyvod-iz-zapoya-v-sankt-peterburge11.ru/ .
bradley pharmacy artane: the pharmacy – grocery store pharmacy
Zestoretic us online pharmacy clomid pioneer rx pharmacy software
buy priligy in usa a The relationship defined by volume of 6 mL LD6
hair loss: online pharmacy viagra uk – cobix generic celebrex pharmacy
This discussion is long overdue—thanks for starting it.오피