透過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,913 Responses

  1. Matthewweind表示:

    generic zithromax over the counter: zithromax best price – zithromax 250 price

  2. Pretty! This was a really wonderful article. Many thanks for supplying this information.

  3. Matthewweind表示:

    ivermectin purchase: stromectol price – ivermectin canada

  4. NicolasLoole表示:

    http://gabapentin.auction/# neurontin 600mg

  5. JeffreyDab表示:

    Look of the Week: Forget the naked dress, Kendall Jenner makes the case for underwear as outerwear
    кракен ссылка

    On Monday, Kendall Jenner stepped out onto the L’Oreal Paris womenswear runway in a scarlet red Mugler gown that might have looked familiar to anyone with a sharp memory of 1999.

    The front of the dress was slashed open across Jenner’s right shoulder, exposing a matching denier bra. The peekaboo moment conjured up memories of another example of fashionable flashing: Lil’ Kim’s purple embellished jumpsuit at the VMAs 26 years earlier. On the red carpet, Kim’s left breast was almost entirely revealed by an asymmetrical cut — a mirror image of Jenner’s neckline — save for a matching purple nipple pasty.
    Jenner’s Mugler moment was just the latest example of a resurging tendency for underwear as outerwear. At the Nensi Dojaka runway show in London earlier this month, boxy blazers were shrugged over strappy bras while paneled bustiers in sheer fabric were paired with capri trousers and reimagined as going out tops. Brasseries were even left exposed to the elements at Erdem — a departure for a house beloved by both British acting royalty (Kristen Scott Thomas) and actual royalty (the Duchess of Cambridge). Dolce & Gabbana got the memo, too, showing satin corsets, garter belts and Madonna-esque cone bras at Milan Fashion Week on Saturday. Florence Pugh even wore one of the label’s risque designs in her first British Vogue cover last week — the circle neckline of her puff-shouldered black dress scooping just above the belly button, acting as a full-frontal frame for her bra.
    But the trend extends beyond just the runways. During the first performance of her “Short n’ Sweet” tour on Monday, singer Sabrina Carpenter took to the stage in a custom Victoria’s Secret bodysuit and stockings. Hand-adorned with over 150,000 crystals, the strapless pink lace-trimmed leotard took over 140 hours to make. On Monday,YouTube star and singer Jojo Siwa inverted the fad by donning a codpiece for a headline-grabbing cover shoot with LadyGunn magazine. The 15th century undergarment was bedazzled with flesh-colored gemstones.

  6. NicolasLoole表示:

    http://semaglutide.win/# order Rybelsus for weight loss

  7. Michaelgax表示:

    zithromax buy online can you buy zithromax over the counter in mexico zithromax over the counter uk

  8. SamuelCic表示:

    https://stromectol.agency/# stromectol tablets 3 mg

  9. NicolasLoole表示:

    https://zithromax.company/# buy zithromax without prescription online

  10. Michaelgax表示:

    generic for amoxicillin Amoxicillin For sale amoxicillin without a doctors prescription

  11. Matthewweind表示:

    Buy semaglutide pills: buy semaglutide online – Rybelsus 14 mg price

  12. NicolasLoole表示:

    http://semaglutide.win/# rybelsus price

  13. Matthewweind表示:

    rybelsus: Rybelsus 14 mg price – Rybelsus 14 mg

  14. Тут делают продвижение разработка медицинских сайтов разработка сайта для медицинского центра

  15. Тут делают продвижение seo-продвижение медицинских сайтов сео продвижение медицинского сайта

  16. SamuelCic表示:

    https://stromectol.agency/# minocycline 50 mg pills online

  17. Stevecoalo表示:

    Look of the Week: Forget the naked dress, Kendall Jenner makes the case for underwear as outerwear
    kraken market

    On Monday, Kendall Jenner stepped out onto the L’Oreal Paris womenswear runway in a scarlet red Mugler gown that might have looked familiar to anyone with a sharp memory of 1999.

    The front of the dress was slashed open across Jenner’s right shoulder, exposing a matching denier bra. The peekaboo moment conjured up memories of another example of fashionable flashing: Lil’ Kim’s purple embellished jumpsuit at the VMAs 26 years earlier. On the red carpet, Kim’s left breast was almost entirely revealed by an asymmetrical cut — a mirror image of Jenner’s neckline — save for a matching purple nipple pasty.
    Jenner’s Mugler moment was just the latest example of a resurging tendency for underwear as outerwear. At the Nensi Dojaka runway show in London earlier this month, boxy blazers were shrugged over strappy bras while paneled bustiers in sheer fabric were paired with capri trousers and reimagined as going out tops. Brasseries were even left exposed to the elements at Erdem — a departure for a house beloved by both British acting royalty (Kristen Scott Thomas) and actual royalty (the Duchess of Cambridge). Dolce & Gabbana got the memo, too, showing satin corsets, garter belts and Madonna-esque cone bras at Milan Fashion Week on Saturday. Florence Pugh even wore one of the label’s risque designs in her first British Vogue cover last week — the circle neckline of her puff-shouldered black dress scooping just above the belly button, acting as a full-frontal frame for her bra.
    But the trend extends beyond just the runways. During the first performance of her “Short n’ Sweet” tour on Monday, singer Sabrina Carpenter took to the stage in a custom Victoria’s Secret bodysuit and stockings. Hand-adorned with over 150,000 crystals, the strapless pink lace-trimmed leotard took over 140 hours to make. On Monday,YouTube star and singer Jojo Siwa inverted the fad by donning a codpiece for a headline-grabbing cover shoot with LadyGunn magazine. The 15th century undergarment was bedazzled with flesh-colored gemstones.

  18. Michaelgax表示:

    zithromax online pharmacy canada order zithromax can i buy zithromax over the counter

  19. Отличный сайт! Всем рекомендую!Оптика СПб

  20. Профессиональный сервисный центр по ремонту моноблоков iMac в Москве.
    Мы предлагаем: мастер по ремонту аймаков
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  21. Kelvinjuile表示:


    Интернет-магазин плитки и керамики «ИнфоПлитка»

    Интернет-магазин керамической плитки и керамогранита «Infoplitka» (infoplitka.ru)
    предлагает широкий ассортимент высококачественной плитки и керамогранита от ведущих производителей.
    Мы стремимся предложить нашим клиентам только лучшее, поэтому в ассортименте представлены товары,
    отвечающие самым высоким стандартам качества и дизайна.

    Мы понимаем, что выбор керамической плитки и керамогранита – это важный этап в создании
    комфортного и стильного интерьера. Поэтому наша команда профессионалов готова помочь вам в
    подборе идеального варианта для вашего проекта. Независимо от того, нужны ли вам плитка
    для ванной комнаты, кухни, гостиной, или же керамогранит для облицовки пола, вы всегда найдете
    у нас разнообразные и актуальные коллекции, соответствующие последним тенденциям в области
    дизайна интерьеров.
    Официальный сайт «ИнфоПлитка»

  22. Gabrielwaimb表示:

    пин ап казино онлайн https://pinupturkey.pro/# pin up bet
    пин ап казино онлайн

  23. ForrestVal表示:

    пинап казино: pin up казино – пин ап казино онлайн

  24. Santopax表示:

    http://pinupkz.tech/# пин ап казахстан

  25. Santopax表示:

    http://pinupaz.bid/# pin up az

  26. Robertdef表示:

    pin up 306 pin-up oyunu pin up casino

  27. Robertdef表示:

    пин ап казино pin up казино pin up казино

  28. ForrestVal表示:

    pin up: pin up az – pin-up kazino

  29. Georgedak表示:

    Вызов сантехника https://santekhnik-moskva.blogspot.com/p/v-moskve.html на дом в Москве и Московской области в удобное для вас время. Сантехнические работы любой сложности, от ремонта унитаза, устранение засора, до замены труб.

發佈留言

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