透過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...

42,263 Responses

  1. beaxy表示:

    In the American League, the Yankees have had their way with the rival Red Sox. Toronto, Tampa, Kansas City, and Seattle also remain undefeated. The Twins went just 32-49 on the road last year, so Zack Greinke and the Royals (+122) could be poised to pull off an Opening Day upset against their AL Central rivals. A three-leg parley on the Astros, Rays and Royals works out to +421 odds. I don’t always want people to take my opinion and run with it, I ALSO want to teach people to understand the process and the bets. I think the team that has home-field advantage in a playoff series between Houston Texas takes the entire American League. No reason to bet Texas (-105) to win the AL West when I genuinely believe the winner takes the AL. If you are one of those people that are DEADSET on Houston winning the AL West, then I would suggest betting them to win the American League as a whole! But I will tell you why I think Texas is the team that takes the division …
    http://front-wiki.win/index.php?title=Top_indian_cricket_betting_site
    After reading this NBA betting guide, you should be able to read and understand an odds table. Being able to read an odds table, however, does not necessarily guarantee betting success. Here are a few tools from The Action Network that can help improve your betting win rate in the NBA. It snapped a nine-game winning streak in Western Conference finals games for Golden State and now it goes home where the Warriors have covered nine of their past 11 games. Dallas is 1-5 ATS its last six road games and 9-4 OVER its past 13 on the road and 12-5 OVER overall against teams with winning records. Go to Survivor Picks » NBA futures are wagers on eventual results regarding certain teams. For example, a NBA championship futures wager is a bet on which team will win the NBA title in June. Other types of NBA futures wagers can involve the number of wins that a team achieves during the season, betting on which team wins their specific division, or betting on which team will win the conference title.

  2. WilliamSoorp表示:

    https://medicinefromindia.store/# indian pharmacy

  3. WilliamPaw表示:

    https://medicinefromindia.store/# indianpharmacy com

  4. WilliamSoorp表示:

    https://edwithoutdoctorprescription.pro/# real cialis without a doctor’s prescription

  5. Eugenehaupe表示:

    cheapest ed pills new ed drugs best ed pills non prescription

  6. Yeah bookmaking this wasn’t a high risk determination great post! .

  7. WilliamSoorp表示:

    http://edpill.cheap/# cure ed

  8. Eugenehaupe表示:

    pharmacy com canada canadapharmacyonline com canadian pharmacy 365

  9. Ded表示:

    New post, liam1352 replied to June 5th – Weekly Winners New post, kelly15268 replied to June 5th – Weekly Winners PLAY AND WIN BIG Welcome to Yebo, the best online casino and online gambling site for South African players. Yebo is a top rated South African online casino with a wide range of online casino games. As a leading South African online casino and we offer frequent online gambling promotions and great casino bonuses. Enjoy the best online gaming experience that is not only fun but also safe and secure. Online gambling in South Africa is growing fast and many gamblers are partaking in some form of online casino gambling. The number of games are the same regardless of whether you play in download or instant play mode. There are 200+ high quality games at this casino, all with exciting graphics and animations. There are slots of different kinds, from brand new RTG slots to some of the tested and popular ones, at this casino. You get the standard classic slots, 5-reel video slots, Real Series slots and progressive slots to play.
    https://polaolympusmentosslot.blogspot.com/
    Exclusive roulette bonus: Unlike other top online roulette casinos, Las Atlantis provides a dedicated roulette bonus with the unique MAELSTROM code. This bonus is a 75% match on your first deposit, and it’s valid for the first five deposits, helping you maximize your gaming experience at this best online roulette site. Just visit any online casino and start playing for free. Some Flash casinos don’t even require you to create an account when playing free roulette games. Just click the roulette table that you want and it’ll be available for play. The best online casino for roulette is Ignition. The site offers a generous welcome bonus that you can use to play eight different roulette games.  Bitcoin was released in 2009, with the first bitcoin-only casinos arriving in 2013 (e.g. Cloudbet). These sites brought new life in to the world of online casinos, with faster withdrawal times and far-improved website design. Later on in 2016, existing casinos like Ignition Casino adopted bitcoin as a payment method alongside their traditional payments too due to it’s permissionless system.

  10. WilliamSoorp表示:

    https://edwithoutdoctorprescription.pro/# buy prescription drugs online without

  11. Eugenehaupe表示:

    indian pharmacy world pharmacy india top 10 pharmacies in india

  12. Eugenehaupe表示:

    best ed pills non prescription male ed pills new treatments for ed

  13. WilliamPaw表示:

    http://medicinefromindia.store/# world pharmacy india

  14. WilliamSoorp表示:

    http://edpill.cheap/# ed drugs

  15. WilliamSoorp表示:

    https://certifiedpharmacymexico.pro/# medicine in mexico pharmacies

  16. Eugenehaupe表示:

    canadian pharmacy price checker canadian family pharmacy canadian pharmacy prices

  17. WilliamSoorp表示:

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

  18. Eugenehaupe表示:

    Online medicine order Online medicine order top online pharmacy india

  19. Ded表示:

    Yes, DoubleDown Casino is a legal online casino game that DoubleDown Interactive, LLC operates. However, players must be at least 18 years old to play DoubleDown Casino, and it is not legal in all jurisdictions. Want more free chips? We give out free bonuses all day, every day! You’ll get top-shelf rewards in our new-and-improved loyalty program, Diamond Club. Take your free Daily Bonus spin, log in to Facebook to share gifts with friends, and follow us on social media to collect free bonus chips and keep the fun going! Please be careful as they take your account or email. And blast with some spam survey, or it might be a potential virus or spyware that can damage your computer system as well. As what sayings say’s when it’s good to be true, you probably won’t. When something wrong happens on your account, double down the casino has nothing to do anymore. So right now, I’m telling you to avoid those kinds of fake rewards. Make sure you double-check someone’s offer on your Facebook newsfeed or the website your on.
    https://kylermlif963963.develop-blog.com/25420803/top-rated-slot-games-with-indian-rupees
    The Fair Go Welcome Bonus matches your deposit 100% up to AUD $200 for new players. The free incentive can be used five times, making the total welcome package worth AUD $1000. The welcome match bonus code can be used even with a minimum deposit of $20 AUD, according to the bonus restrictions. Furthermore available are some fantastic Fair Go no deposit offers. For the most Australian-style excitement, be sure to add the Fair Go casino emblem to your home screen. You may find sites like Fair Go Casino that put pokie machines into different categories. Online slots may fall into different slot types like 3D slots, classic fruit machines with 3 or 5 reels or video slots. There are many ways to group them – these seem to be the most popular ones. Progressive jackpot slots are also something that real players would take into account when visiting Fair Go Casino.

  20. WilliamSoorp表示:

    https://canadianinternationalpharmacy.pro/# canadian neighbor pharmacy

  21. Eugenehaupe表示:

    buying prescription drugs in mexico mexico drug stores pharmacies purple pharmacy mexico price list

  22. Eugenehaupe表示:

    best canadian pharmacy safe canadian pharmacy adderall canadian pharmacy

  23. BennyNib表示:

    reputable mexican pharmacies online: medicine in mexico pharmacies – medicine in mexico pharmacies

  24. WilliamSoorp表示:

    https://certifiedpharmacymexico.pro/# pharmacies in mexico that ship to usa

  25. WilliamPaw表示:

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

  26. BennyNib表示:

    online pharmacy india: top online pharmacy india – indianpharmacy com

  27. Ded表示:

    You can be sure all the shortlisted casinos here also offer a full and diverse games lobby. We’ve recommended the best online casinos around that offer the top online gaming experience for gamblers of all types. Take a look at our top 5 list where you can play online slots, card games like blackjack and poker, as well as roulette, baccarat, craps, and many other casino games for real money. We’ve picked the most popular casinos and grouped them by the playing platforms they use: RTG, Microgaming, and Playtech. casinos for us players are accepting US Players and then there are casinos that do not accept USA players for rela money. RTG Casinos allow american players. We have already started collecting information about responsible gambling options – such as self-exclusion, betting limits, reality checks, and more – available at individual online casinos. However, because of the vastness of our database, we do not have the data collected for all casino sites. Once we have it, we will include this information in our review of each casino.
    https://www.mazafakas.com/user/profile/2932748
    The sweepstakes model Chumba Casino provides offers players the opportunity to play casino games using virtual currencies, and although there’s no real money involved and the platform doesn’t offer a live dealer experience, Chumba Casino online reviews show it still provides an authentic casino experience. However, If you’re looking for real-time action with live dealers, you can check out our review of Stake. Chumba Casino is accessible through an internet browser, meaning you do not have to download any software to begin playing. While there is no mobile app, players can access free to play Chumba Casino on their phones and tablet devices via any internet browser. Gold coins are provided for free to all Chumba Casino players and can also be purchased for real money. They do not hold any real value, but players can use them to find the best Chumba slots. Then, using the precious sweeps coins in their arsenal, they can multiply their balance and redeem them for real cash prizes.

  28. WilliamSoorp表示:

    http://certifiedpharmacymexico.pro/# buying prescription drugs in mexico

  29. BennyNib表示:

    viagra without a doctor prescription walmart: cheap cialis – viagra without a doctor prescription

  30. Eugenehaupe表示:

    buy prescription drugs online cialis without a doctor prescription canada prescription drugs without doctor approval

發佈留言

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