透過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」的訊息:

Cross doamin XML access

但如果套用上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>
Cross doamin XML access

可以看到已經可以抓到XML內容,這樣可以讓我們較為方便的去開發,其他詳細的使用說明可以參考Yahoo YQL Guide

You may also like...

46,401 Responses

  1. WilliamSoorp表示:

    http://edpill.cheap/# ed pills that work

  2. BennyNib表示:

    mexican rx online: medication from mexico pharmacy – mexican border pharmacies shipping to usa

  3. WilliamPaw表示:

    http://medicinefromindia.store/# cheapest online pharmacy india

  4. Eugenehaupe表示:

    canadian pharmacy sarasota legitimate canadian pharmacy online canadian pharmacy scam

  5. WilliamSoorp表示:

    http://medicinefromindia.store/# mail order pharmacy india

  6. Ded表示:

    Most leading gambling apps use Real Time Gaming as their software provider. RTG is among the most reliable providers in the gaming industry. Betsoft is also a unique software provider, and it is used by the top real-money online casinos like Cafe Casino. You can’t go wrong if you pick the online casino app embarked on by one of these reliable software providers. One of the primary reasons an individual should choose an online casino real money platform over traditional casinos in 2023 is the convenience and accessibility associated with these platforms. With an online casino real money platform, an individual can access games from anywhere with an internet connection. Variety: The variety of ignition casinos is among the best in the industry. This online casino games site provides 17 poker games, enough to let you play for the whole day without getting bored with a single game. They also offer many free games too.
    https://turkcebahissiteleri9.com/review/tipobet365/
    BoVegas offers games from RTG. Most of the games provided possesses a bonus round making the amount of free funds that can be claimed by players from the casino unimaginable. A support team is provided to players on a 24 hours basis every day of the year. The site possesses an instant play platform making it easy for players to game from any part of the world at any time. With the wide network the casino possesses, players from the US and other parts of the world can register with the platform. To get more details about the bonus offered at the BoVegas gambling den, stick with this review for a while. Copyright © All rights reserved | Nabble Casino Bingo Bonus Codes | 2024 Read our review of Bovegas Casino I have successfully received payouts from BoVegas, but I’m frustrated they don’t process any withdrawal for at least 3 business days. Bitcoin shouldn’t take more than a day from any casino these days. You can cash out up to $2,000 per week, which will force you to make other arrangements with the casino if you hit a big jackpot. I am pleased that BoVegas will send withdrawals directly to your bank account via bank wire.

  7. Ded表示:

    Online casino gaming has never been a safer experience than with Grand Fortune Casino. Concerns about sharing personal information online are understandable, but here there’s no need to fear. Your security is a top priority and the casino goes to great lengths to keep you protected. We advise players to find better U.S.A. friendly options. There are many choices powered by the same popular RTG software. If you decide to go ahead with another Virtual Casino site, then Raging Bull will be the closest sister to Grand Fortune. You will not find much difference regarding the very player friendly gaming platforms or for that matter the range of casino games at each of the similar sites to Grand Fortune Casino for they all operate using the tried and test Real Time Gaming software platforms and that companies range of games too.
    https://zenwriting.net/lycrakorean58/acquire-expertise-on-slot-video-games-via-cost-free-no-download-mobile-slot
    Another advantage of online casinos is that they can cost you less in the long run, particularly if you enjoy Oklahoma slot machines or other Oklahoma casino games of chance. The reason is that the theoretical returned to player (RTP) at online casinos is higher (often 95%-97%) compared to land-based casinos that can drop below 80%. Furthermore, the choice of slots at an online casino like Red Dog tends to dominate its land-based cousin. Getting the bonus is almost always very easy. You simply need to register your details with the casino in question and then either a) enter a bonus code b) contact the casino requesting the bonus or c) simply wait for the bonus to appear in your casino account after registration. Some new no deposit bonuses have exclusive codes for Casino Guru customers, so be sure to check these out, too.

  8. Eugenehaupe表示:

    online shopping pharmacy india pharmacy website india indian pharmacy

  9. WilliamSoorp表示:

    https://certifiedpharmacymexico.pro/# mexican drugstore online

  10. Eugenehaupe表示:

    best ed medication ed pills online cheap ed pills

  11. WilliamSoorp表示:

    http://certifiedpharmacymexico.pro/# purple pharmacy mexico price list

  12. WilliamSoorp表示:

    https://edpill.cheap/# erectile dysfunction drug

  13. Eugenehaupe表示:

    generic viagra without a doctor prescription cheap cialis buy prescription drugs from india

  14. Eugenehaupe表示:

    erectile dysfunction pills best ed medication п»їerectile dysfunction medication

  15. WilliamSoorp表示:

    https://medicinefromindia.store/# online shopping pharmacy india

  16. Отличный сайт! Всем рекомендую!купить аттестат

  17. Eugenehaupe表示:

    buying ed pills online ed meds online without doctor prescription ed drug prices

  18. WilliamSoorp表示:

    http://canadianinternationalpharmacy.pro/# best online canadian pharmacy

  19. Eugenehaupe表示:

    india pharmacy indian pharmacies safe Online medicine order

  20. WilliamSoorp表示:

    http://certifiedpharmacymexico.pro/# mexico pharmacies prescription drugs

  21. Kwjasd表示:

    viagra 100mg cost sildenafil pharmacy buy sildenafil 100mg for sale

  22. WilliamSoorp表示:

    https://edwithoutdoctorprescription.pro/# buy prescription drugs from canada cheap

  23. Eugenehaupe表示:

    mexico drug stores pharmacies purple pharmacy mexico price list pharmacies in mexico that ship to usa

  24. WilliamSoorp表示:

    http://medicinefromindia.store/# cheapest online pharmacy india

  25. Eugenehaupe表示:

    online ed medications best ed medication ed medications online

  26. WilliamSoorp表示:

    http://edwithoutdoctorprescription.pro/# non prescription erection pills

  27. BennyNib表示:

    best over the counter ed pills: herbal ed treatment – natural ed medications

  28. Eugenehaupe表示:

    ed meds online without doctor prescription cialis without a doctor prescription buy prescription drugs without doctor

  29. WilliamSoorp表示:

    http://canadianinternationalpharmacy.pro/# canadian pharmacy online

  30. Eugenehaupe表示:

    mail order pharmacy india india online pharmacy buy prescription drugs from india

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。