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

51,869 Responses

  1. Perryzoozy表示:

    pharmacie en ligne france pas cher cialis generique pharmacie en ligne

  2. Phillipedugs表示:

    Look of the Week: Kendrick Lamar’s Super Bowl pants signal the return of flares
    kraken вход
    This year’s Super Bowl halftime show was hardly a fashion extravaganza, with headliner Kendrick Lamar keeping things simple in a backwards cap and motorbike-style varsity jacket, which he kept on throughout.

    And without the costume-change roulette we’ve come to expect of halftime shows, the internet fixated on one item in particular: his jeans.

    While not quite the bell-bottoms of decades past (the 1970s and the 2000s, specifically), the Compton-born rapper’s washed denim pants flared out at the knee and dragged beneath his heels along the stage at Caesars Superdrome in New Orleans. His silhouette stood in stark contrast to that of record producer Mustard, who made a brief cameo in a pair of outsized jeans straight from the West Coast hip-hop playbook.
    Opinions were, as ever, divided on social media. Some users described Lamar’s flares as “women’s jeans” and “Hannah Montana pants,” earning him comparisons to everyone from Jennifer Aniston to country singer Lainey Wilson. Others joked that their moms were looking for a similar pair or that they nodded to millennials, for whom flares were a teenage staple.

    But those suggesting his style was outdated, or gender-inappropriate, may not have been paying attention to the recent resurgence of flares — in both womenswear and menswear. After all, Lamar’s jeans were designed by one of the most influential figures in modern fashion, Celine’s former creative director Hedi Slimane, before he departed the French label in October.

  3. GeorgeHal表示:

    этот сайт rox casino

  4. WilsonVah表示:

    trouver un mГ©dicament en pharmacie: pharmacie en ligne pas cher – п»їpharmacie en ligne france

  5. Jacobbep表示:

    Pharmacie sans ordonnance https://pharmaciemeilleurprix.com/# pharmacie en ligne france livraison belgique

  6. GeorgeHal表示:

    нажмите здесь rox casino

  7. WilsonVah表示:

    acheter mГ©dicament en ligne sans ordonnance: cialis prix – pharmacie en ligne

  8. Kevinalgon表示:

    Scores of unexploded World War II bombs discovered under children’s playground
    lucky jet играть
    Scores of unexploded bombs dating from World War II have been recovered from a children’s playground in northern England after a chance discovery.

    Local officials in the town of Wooler, Northumberland called in bomb disposal experts after workers involved in a planned overhaul of Scotts Play Park found unexploded ordnance, the parish council said in a statement sent to CNN on Monday.

    Two bombs were initially removed by the British Army, the UK Ministry of Defense said in a statement. The parish council was then advised that a full survey of the area was required, according to a council spokesperson.
    Bomb disposal company Brimstone Site Investigation then uncovered 65 10-pound practice bombs and smoke cartridges on the first day of works, with a further 90 practice bombs recovered on the second day.

    The company told CNN that the bombs date from World War II.

    According to the parish council, all of the bombs need to be found and removed before the park can be reopened. It said 174 devices had been found so far.

  9. NorbertKep表示:

    pharmacie en ligne sans ordonnance: cialis prix – Pharmacie sans ordonnance

  10. Jacobbep表示:

    pharmacie en ligne sans ordonnance https://tadalafilmeilleurprix.shop/# pharmacie en ligne fiable

  11. Jacobbep表示:

    pharmacie en ligne livraison europe https://viagrameilleurprix.shop/# Acheter viagra en ligne livraison 24h

  12. Jacobbep表示:

    pharmacie en ligne livraison europe http://pharmaciemeilleurprix.com/# pharmacie en ligne avec ordonnance

  13. WilsonVah表示:

    trouver un mГ©dicament en pharmacie: Acheter Cialis – Pharmacie Internationale en ligne

  14. Ricardoverve表示:

    выберите ресурсы 1хслотс

  15. Perryzoozy表示:

    Quand une femme prend du Viagra homme Viagra sans ordonnance 24h Amazon SildГ©nafil 100mg pharmacie en ligne

  16. Kevinjef表示:

    Cute baby animals bring visitors to zoos and aquariums. What happens when they grow up?
    арбитраж трафика
    One of the best things that can happen to a zoo or aquarium is for one of their resident animals to go viral.

    Just look at the multi-hour-long lines to see Moo Deng, a pygmy hippo in Thailand who has become an internet sensation following her July 2024 birth. The sassy animal is now a full-on brand, with Khao Kheow Open Zoo selling Moo Deng merchandise and even releasing a single “by” the hippo in multiple languages.

    Meanwhile, Pesto — a baby king penguin who was eating more fish than his parents by the time he was a few weeks old — is also an online celebrity, with human stars like Olivia Rodrigo and Katy Perry stopping by to meet him.

    But what happens when these cute animals become, well, less cute? The Sea Life Melbourne aquarium has already been planning for the next phase of Pesto’s life — and answering questions from the public about his changing appearance.

    It’s normal for king penguins to lose their feathers by the time they’re about a year old and become confident swimmers. As a result, a spokesperson for the aquarium says, guests have started asking why Pesto looks different — or why they can’t find him at all.

    “We are getting a few guests thinking we have moved him off display completely,” says the spokesperson. “Most of the team’s time is spent pointing him out to guests because he looks so different now.”
    The bottom line is that cute baby animals make money.

    Admission tickets are only the beginning. Many zoos and aquariums offer special “behind the scenes” or “zookeeper for a day” packages at much higher prices. At Sea Life Melbourne, standard entry tickets for adults start at $51, while the Penguin Passport — which include a 45-minute tour of the birds’ area and a look at how their food is prepared — is $199.

    The real jackpot, though, is merchandise. Stuffed animals, T-shirts, fridge magnets, keychains, kids’ books and other branded products are a major way for zoos and aquariums to make money.

  17. MichaelDromb表示:

    Look of the Week: Kendrick Lamar’s Super Bowl pants signal the return of flares
    кракен даркнет
    This year’s Super Bowl halftime show was hardly a fashion extravaganza, with headliner Kendrick Lamar keeping things simple in a backwards cap and motorbike-style varsity jacket, which he kept on throughout.

    And without the costume-change roulette we’ve come to expect of halftime shows, the internet fixated on one item in particular: his jeans.

    While not quite the bell-bottoms of decades past (the 1970s and the 2000s, specifically), the Compton-born rapper’s washed denim pants flared out at the knee and dragged beneath his heels along the stage at Caesars Superdrome in New Orleans. His silhouette stood in stark contrast to that of record producer Mustard, who made a brief cameo in a pair of outsized jeans straight from the West Coast hip-hop playbook.
    Opinions were, as ever, divided on social media. Some users described Lamar’s flares as “women’s jeans” and “Hannah Montana pants,” earning him comparisons to everyone from Jennifer Aniston to country singer Lainey Wilson. Others joked that their moms were looking for a similar pair or that they nodded to millennials, for whom flares were a teenage staple.

    But those suggesting his style was outdated, or gender-inappropriate, may not have been paying attention to the recent resurgence of flares — in both womenswear and menswear. After all, Lamar’s jeans were designed by one of the most influential figures in modern fashion, Celine’s former creative director Hedi Slimane, before he departed the French label in October.

  18. Kennethphink表示:

    Scores of unexploded World War II bombs discovered under children’s playground
    сайт lucky jet
    Scores of unexploded bombs dating from World War II have been recovered from a children’s playground in northern England after a chance discovery.

    Local officials in the town of Wooler, Northumberland called in bomb disposal experts after workers involved in a planned overhaul of Scotts Play Park found unexploded ordnance, the parish council said in a statement sent to CNN on Monday.

    Two bombs were initially removed by the British Army, the UK Ministry of Defense said in a statement. The parish council was then advised that a full survey of the area was required, according to a council spokesperson.
    Bomb disposal company Brimstone Site Investigation then uncovered 65 10-pound practice bombs and smoke cartridges on the first day of works, with a further 90 practice bombs recovered on the second day.

    The company told CNN that the bombs date from World War II.

    According to the parish council, all of the bombs need to be found and removed before the park can be reopened. It said 174 devices had been found so far.

  19. Richardprurf表示:

    http://pharmaciemeilleurprix.com/# acheter mГ©dicament en ligne sans ordonnance
    Pharmacie en ligne livraison Europe

  20. WilsonVah表示:

    trouver un mГ©dicament en pharmacie: pharmacie en ligne pas cher – Achat mГ©dicament en ligne fiable

  21. NorbertKep表示:

    pharmacies en ligne certifiГ©es: kamagra en ligne – pharmacie en ligne france livraison belgique

  22. MarcoFieri表示:

    посетить веб-сайт riobet

  23. Perryzoozy表示:

    pharmacie en ligne avec ordonnance acheter kamagra site fiable Pharmacie Internationale en ligne

  24. Perryzoozy表示:

    Pharmacie sans ordonnance pharmacie en ligne pas cher pharmacie en ligne

  25. WilsonVah表示:

    pharmacie en ligne france pas cher: cialis prix – pharmacies en ligne certifiГ©es

發佈留言

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