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

49,326 Responses

  1. BradleyEdino表示:

    slot oyunlar? en kazancl? slot oyunlar? az parayla cok kazandiran slot oyunlar?

  2. Mathewnus表示:

    Introducing the Zircuit Token System
    The Zircuit token, a pivotal element in the blockchain landscape, plays a crucial role in enabling efficient transactions and offering enhanced security. Designed for seamless integration into various platforms, it aims to revolutionize the way digital currencies are perceived and utilized.
    zircuit funding
    Key Advantages of the Zircuit Token
    Enhanced Security: Security is a core benefit of utilizing the Zircuit token. By employing advanced cryptographic techniques, it ensures that transactions are secure, safeguarding user data and funds from potential threats.
    Scalable Transactions: Zircuit token is engineered for scalability, allowing for a large number of transactions per second. This capability promises efficiency even as user numbers grow, ensuring smooth operations across digital platforms.
    Low Transaction Fees: One of the significant advantages of using the Zircuit token is the cost-effectiveness of its transactions. It boasts lower fees compared to traditional financial systems, making it an attractive option for users.
    Implementing Zircuit Tokens in Everyday Use
    The implementation of Zircuit tokens into daily transactions is designed to be straightforward. Users can manage their tokens seamlessly through dedicated wallets that offer user-friendly interfaces and robust security. Thanks to its decentralized nature, it enables trustless interactions, where intermediaries are reduced, thereby minimizing costs and enhancing speed.

    Furthermore, Zircuit tokens offer compatibility with various platforms, allowing users to transact with ease across a plethora of services. This flexibility is crucial for both individuals and businesses looking to integrate blockchain technology into their operations.

    In conclusion, the Zircuit token stands as a testament to the evolving nature of digital currencies, offering a secure, scalable, and cost-effective solution for modern financial transactions. As adoption continues to grow, the robustness of the Zircuit token system is likely to play a critical role in shaping the future of digital exchanges.

  3. JasonUnsoG表示:

    https://casinositeleri25.com/# en guvenilir casino siteleri

  4. Wallacefex表示:

    deneme bonusu veren siteler: deneme bonusu veren yeni siteler – yeni deneme bonusu veren siteler

  5. Exchange Fee-a fee that some funds impose on shareholders if they exchange (transfer) to another fund within the same “family of funds”.

  6. GreggRom表示:

    A brief history of sunglasses, from Ancient Rome to Hollywood
    кракен вход

    Sunglasses, or dark glasses, have always guarded against strong sunlight, but is there more to “shades” than we think?

    The pupils of our eyes are delicate and react immediately to strong lights. Protecting them against light — even the brilliance reflected off snow — is important for everyone. Himalayan mountaineers wear goggles for this exact purpose.

    Protection is partly the function of sunglasses. But dark or colored lens glasses have become fashion accessories and personal signature items. Think of the vast and famous collector of sunglasses Elton John, with his pink lensed heart-shaped extravaganzas and many others.

    When did this interest in protecting the eyes begin, and at what point did dark glasses become a social statement as well as physical protection?
    The Roman Emperor Nero is reported as holding polished gemstones to his eyes for sun protection as he watched fighting gladiators.

    We know Canadian far north Copper Inuit and Alaskan Yupik wore snow goggles of many kinds made of antlers or whalebone and with tiny horizontal slits. Wearers looked through these and they were protected against the snow’s brilliant light when hunting. At the same time the very narrow eye holes helped them to focus on their prey.

    In 12th-century China, judges wore sunglasses with smoked quartz lenses to hide their facial expressions — perhaps to retain their dignity or not convey emotions.

  7. BradleyEdino表示:

    gore siteler Casino Siteleri deneme bonusu veren casino siteleri

  8. Incomplete solutions are awarded an appropriate proportion of the points obtainable.

  9. JasonUnsoG表示:

    https://casinositeleri25.com/# casino bahis siteleri

  10. FrankEmine表示:

    guvenilir slot siteleri: guvenilir slot siteleri – slot oyunlar? puf noktalar?

  11. JasonUnsoG表示:

    https://slotsiteleri25.com/# az parayla cok kazandiran slot oyunlar?

  12. What does matter here is that you need to make an accurate prediction.

  13. Wallacefex表示:

    sweet bonanza yorumlar: sweet bonanza kazanma saatleri – sweet bonanza oyna

  14. рейтинг процессоров amd https://topcpu.ru/ .

  15. сравнение производительности процессоров http://www.topcpu.ru/ .

  16. рейтинги процессоров для пк [url=http://topcpu.ru/]http://topcpu.ru/[/url] .

  17. RichardHot表示:

    Альткоин – Alt coin cc, альткоин bestchange

  18. tk999 _weKn表示:

    tk 999 login [url=www.onlineuaeuniversities.org/]tk 999 login[/url] .

  19. RichardHot表示:

    Альткоин обменник крипты – Alt coin cc обменник, Альткоин

  20. FrankEmine表示:

    sweet bonanza slot: sweet bonanza yorumlar – sweet bonanza yorumlar

  21. Thomasnit表示:

    обмен биткойнов – обменять эфириум, где купить usdt

  22. Wallacefex表示:

    guvenilir slot siteleri: az parayla cok kazandiran slot oyunlar? – slot siteleri

  23. Wallacefex表示:

    en guvenilir casino siteleri: deneme bonusu veren casino siteleri – casino bahis siteleri

  24. Thomasnit表示:

    купить eth – ferma cc обменник, торговля криптовалютой

  25. RichardHot表示:

    Альткоин бестчейдж – Альт коин обменник, Alt coin cc обменник

發佈留言

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