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

41,779 Responses

  1. Darrelherse表示:

    deneme bonusu veren slot siteleri: en yeni slot siteleri – slot oyun siteleri

  2. Fyliob表示:

    mebeverine over the counter – arcoxia tablet pletal 100 mg canada

  3. Harry Potter becomes headmaster in his final year at school.

  4. Very good info. Lucky me I found your website by accident (stumbleupon). I have book marked it for later.

  5. I’m often to blogging and i really respect your content. The article has actually peaks my interest. I’m going to bookmark your site and preserve checking for brand spanking new information.

  6. Stephenideox表示:

    This form of business can be chosen by different types of business entities such as trusts, corporations, and individuals. LLCs do not put the assets of their shareholders at risk by separating personal liabilities from those created by the company. The establishment of a limited liability company in Europe often requires the preparation of incorporation documents, the deposit of a minimum share capital, and registration with the Commercial Register. The management of the LLC is usually entrusted to the members (directors and shareholders), but in some cases the decision-making power in the company may be delegated from the founders of the business to hired managers.
    Opening an LLC in Europe offers many advantages, the most attractive of which is the limited liability of the owners. This means that in case something goes wrong, the owner will be liable for the company’s debts up to the amount of the authorised capital. Another important advantage of choosing a limited liability company is the capital that is required at incorporation. Many European countries have reduced the authorised capital requirements for this type of company. One of the best examples in this case is the Netherlands: those who want to open a Dutch limited company only need €1 as authorised capital. Of course, the total costs will be higher, but the Netherlands remains one of the cheapest European countries to start a company.

  7. GlennSaunk表示:

    Les avocats et conseillers financiers Fintech de RUE (Regulated United Europe) ont cree un blog ou ils publient les dernieres modifications de la legislation des pays europeens dans le domaine de la crypto-monnaie et du VASP (Virtual Asset Fournisseur de services) pour la commodite et l’information de tous ceux qui s’interessent a la legislation europeenne sur les crypto-monnaies. Nous basons nos articles sur des sujets importants pour les entrepreneurs d’aujourd’hui travaillant dans le domaine de la crypto-monnaie, des projets fintech, de la blockchain et des entreprises liees a l’informatique. Si vous ne trouvez pas les informations qui vous interessent sur notre blog, veuillez nous contacter de la maniere qui vous convient.

  8. Hermanswoff表示:

    medicine in mexico pharmacies: best online pharmacies in mexico – п»їbest mexican online pharmacies

  9. JeremyPsymn表示:

    http://easyrxindia.com/# india online pharmacy

  10. Peterhew表示:

    legitimate canadian pharmacy: canadian pharmacy tampa – canadian pharmacy meds reviews

  11. Thank you for every other informative blog. Where else could I get that kind of information written in such a perfect manner? I’ve a mission that I’m just now operating on, and I have been on the look out for such information.

  12. SBC, which began as the Baby Bell named Southwestern Bell, invested in expanding its services to include data, video and voice.

  13. Peterhew表示:

    online shopping pharmacy india: Online medicine home delivery – reputable indian online pharmacy

  14. I just like the valuable information you supply to your articles. I?ll bookmark your weblog and check once more here regularly. I am reasonably sure I?ll learn plenty of new stuff right right here! Good luck for the next!

  15. When I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I receive 4 emails with the exact same comment. Is there a way you are able to remove me from that service? Thank you.

  16. Heath, Thomas. “Meet the one guy who’s happy in regards to the wild swings in the stock market”.

  17. Robertengep表示:

    http://easyrxcanada.com/# legitimate canadian mail order pharmacy

  18. hello there and thanks to your information ? I?ve certainly picked up something new from right here. I did then again experience a few technical issues using this website, as I skilled to reload the web site lots of instances prior to I could get it to load correctly. I were wondering if your web host is OK? Not that I am complaining, but slow loading instances times will very frequently have an effect on your placement in google and can injury your quality rating if ads and ***********|advertising|advertising|advertising and *********** with Adwords. Well I?m adding this RSS to my e-mail and could look out for much extra of your respective intriguing content. Make sure you replace this once more very soon..

  19. 33win表示:

    When I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive four emails with the exact same comment. Is there an easy method you can remove me from that service? Thank you.

  20. Discover the perfect blend of style and comfort at marmot clothing.

  21. Rochelle表示:

    Also visit my webpage; Daycare Near Me (Rochelle)

  22. Robertengep表示:

    https://mexstarpharma.online/# mexican rx online

發佈留言

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