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

  1. KeithMup表示:

    7 simple secrets to eating the Mediterranean way
    kraken зеркало
    What if “diet” wasn’t a dirty word?

    During Suzy Karadsheh’s childhood in Port Said, Egypt, diet culture was nonexistent.

    “My parents emphasized joy at the table, rather than anything else,” Karadsheh said. “I grew up with Mediterranean lifestyle principles that celebrate eating with the seasons, eating mostly whole foods and above all else, sharing.”

    But when Karadsheh moved to the United States at age 16, she witnessed people doing detoxes or restricting certain food groups or ingredients. Surrounded by that narrative and an abundance of new foods in her college dining hall, she says she “gained the freshman 31 instead of the freshman 15.” When she returned home to Egypt that summer, “I eased back into eating the Mediterranean food that I grew up with. During the span of about two months, I shed all of that weight without thinking I was ever on a diet.”
    To help invite joy back to the table for others — and to keep her family’s culinary heritage alive for her two daughters (now 14 and 22) — Atlanta-based Karadsheh launched The Mediterranean Dish food blog 10 years ago. Quickly, her table started getting filled with more than just her friends and family.

    “I started receiving emails from folks whose doctors had prescribed the Mediterranean diet and were seeking approachable recipes,” Karadsheh said. The plant-based eating lifestyle, often rated the world’s best diet, can reduce the risk for diabetes, high cholesterol, dementia, memory loss and depression, according to research. What’s more, the meal plan has been linked to stronger bones, a healthier heart and longer life.

    Preparing meals the Mediterranean way, according to Karadsheh, can help you “eat well and live joyfully. To us, ‘diet’ doesn’t mean a list of ‘eat this’ and ‘don’t eat that.’” Instead of omission, Karadsheh focuses on abundance, asking herself, “what can I add to my life through this way of living? More whole foods, vegetables, grains, legumes? Naturally, when you add these good-for-you ingredients, you eat less of what’s not as health-promoting,” she told CNN.

  2. DennisKah表示:

    buy medicines online in india: india pharmacy mail order – online pharmacy india

  3. Jeremymes表示:

    Sea robins are fish with ‘the wings of a bird and multiple legs like a crab’
    kra9 cc
    Some types of sea robins, a peculiar bottom-dwelling ocean fish, use taste bud-covered legs to sense and dig up prey along the seafloor, according to new research.

    Sea robins are so adept at rooting out prey as they walk along the ocean floor on their six leglike appendages that other fish follow them around in the hope of snagging some freshly uncovered prey themselves, said the authors of two new studies published Thursday in the journal Current Biology.

    David Kingsley, coauthor of both studies, first came across the fish in the summer of 2016 after giving a seminar at the Marine Biological Laboratory in Woods Hole, Massachusetts. Kingsley is the Rudy J. and Daphne Donohue Munzer Professor in the department of developmental biology at Stanford University’s School of Medicine.

    Before leaving to catch a flight, Kingsley stopped at a small public aquarium, where he spied sea robins and their delicate fins, which resemble the feathery wings of a bird, as well as leglike appendages.

    “The sea robins on display completely spun my head around because they had the body of a fish, the wings of a bird, and multiple legs like a crab,” Kingsley said in an email.
    “I’d never seen a fish that looked like it was made of body parts from many different types of animals.”
    Kingsley and his colleagues decided to study sea robins in a lab setting, uncovering a wealth of surprises, including the differences between sea robin species and the genetics responsible for their unusual traits, such as leglike fins that have evolved so that they largely function as sensory organs.

    The findings of the study team’s new research show how evolution leads to complex adaptations in specific environments, such as the ability of sea robins to be able to “taste” prey using their quickly scurrying and highly sensitive appendages.

  4. WilliamTut表示:

    Comet likely last seen when Neanderthals walked Earth could soon dazzle in the night sky
    Смартфон Samsung Galaxy S22 5G 8GB/128GB графитовый SM-S901B/DS купить в Гродно
    A recently discovered comet, known as C/2023 A3 Tsuchinshan–ATLAS, will make its closest approach of Earth on Saturday. Sky-gazers won’t want to miss the event since it may be the last time the comet will be seen in the night sky for another 80,000 years.

    The comet successfully reached perihelion, its closest point to the sun in its orbital path around the parent star, on September 27, and was visible for those in the Southern Hemisphere in September and early October. Now, the icy body is on its way out of the inner solar system and will be visible to those in the Northern Hemisphere in mid-October through early November, according to NASA.

    On Saturday, the comet will come within about 44 million miles (nearly 71 million kilometers) of Earth. The comet is making its first documented flyby of our planet, according to NASA. With its 80,000-year orbit, the celestial body would have been last seen from Earth at the time of the Neanderthals.
    Those looking to catch a glimpse of the once-in-a-lifetime event will want to look in the western part of the night sky, shortly after sunset, according to EarthSky.

    The comet will look like a bright fireball in the dark sky with a long, extended tail. Bill Cooke, lead of NASA’s Meteoroid Environment Office at the Marshall Space Flight Center in Huntsville, Alabama, recommends a pair of binoculars for enhanced viewing of the comet.

    “It’s not going to zing across the sky like a meteor. It will just appear to hang there, and it will slowly change position from night to night,” Cooke said. “If you can see (the comet) with your unaided eye, (using) the binoculars will knock your socks off.”

  5. BrandonJer表示:

    top ed drugs erectile dysfunction natural remedies medicines for ed

  6. Gregorypurne表示:

    erectile dysfunction https://mexicanpharm24.pro/# mexico drug stores pharmacies

  7. AgustinBougs表示:

    https://mexicanpharm24.pro/# mexican drugstore online
    top 10 pharmacies in india

  8. Gregorypurne表示:

    generic ed drugs http://indianpharmdelivery.com/# india pharmacy

  9. DennisKah表示:

    indianpharmacy com: reputable indian pharmacies – indian pharmacies safe

  10. General Notes: Husband – Rufus Robinson Feel free to Download my Info, and if you happen to discover a hyperlink, please e-mail me to let me know.

  11. KeithMup表示:

    7 simple secrets to eating the Mediterranean way
    kra8 gl
    What if “diet” wasn’t a dirty word?

    During Suzy Karadsheh’s childhood in Port Said, Egypt, diet culture was nonexistent.

    “My parents emphasized joy at the table, rather than anything else,” Karadsheh said. “I grew up with Mediterranean lifestyle principles that celebrate eating with the seasons, eating mostly whole foods and above all else, sharing.”

    But when Karadsheh moved to the United States at age 16, she witnessed people doing detoxes or restricting certain food groups or ingredients. Surrounded by that narrative and an abundance of new foods in her college dining hall, she says she “gained the freshman 31 instead of the freshman 15.” When she returned home to Egypt that summer, “I eased back into eating the Mediterranean food that I grew up with. During the span of about two months, I shed all of that weight without thinking I was ever on a diet.”
    To help invite joy back to the table for others — and to keep her family’s culinary heritage alive for her two daughters (now 14 and 22) — Atlanta-based Karadsheh launched The Mediterranean Dish food blog 10 years ago. Quickly, her table started getting filled with more than just her friends and family.

    “I started receiving emails from folks whose doctors had prescribed the Mediterranean diet and were seeking approachable recipes,” Karadsheh said. The plant-based eating lifestyle, often rated the world’s best diet, can reduce the risk for diabetes, high cholesterol, dementia, memory loss and depression, according to research. What’s more, the meal plan has been linked to stronger bones, a healthier heart and longer life.

    Preparing meals the Mediterranean way, according to Karadsheh, can help you “eat well and live joyfully. To us, ‘diet’ doesn’t mean a list of ‘eat this’ and ‘don’t eat that.’” Instead of omission, Karadsheh focuses on abundance, asking herself, “what can I add to my life through this way of living? More whole foods, vegetables, grains, legumes? Naturally, when you add these good-for-you ingredients, you eat less of what’s not as health-promoting,” she told CNN.

  12. The promotion of panel and box cookers is usually aimed toward households and refugees, while the more subtle parabolic cookers are generally reserved for big-scale cooking in institutions.

  13. Individuals love to offer on a day known as Giving Tuesday.

  14.  Cally Whitt requests prayers for her sister, Tammy Hunt, who had surgical procedure to take away part of her colon as a result of cancer.

  15. 著者の方表示:

    Jazzed up paper pinwheels in numerous patterns and sizes creates the illusion of a fireworks show proper in your entrance door.

  16. BrandonJer表示:

    pharmacies in mexico that ship to usa reputable mexican pharmacies online buying from online mexican pharmacy

  17. SamuelPogma表示:

    Automatic takeoffs are coming for passenger jets and they’re going to redraw the map of the sky
    kra8 cc

    In late 1965, at what’s now London Heathrow airport, a commercial flight coming from Paris made history by being the first to land automatically.

    The plane – A Trident 1C operated by BEA, which would later become British Airways – was equipped with a newly developed extension of the autopilot (a system to help guide the plane’s path without manual control) known as “autoland.”

    Today, automatic landing systems are installed on most commercial aircraft and improve the safety of landings in difficult weather or poor visibility.

    Now, nearly 60 years later, the world’s third largest aircraft manufacturer, Brazil’s Embraer, is introducing a similar technology, but for takeoffs.

    Called “E2 Enhanced Take Off System,” after the family of aircraft it’s designed for, the technology would not only improve safety by reducing pilot workload, but it would also improve range and takeoff weight, allowing the planes that use it to travel farther, according to Embraer.

    “The system is better than the pilots,” says Patrice London, principal performance engineer at Embraer, who has worked on the project for over a decade. ”That’s because it performs in the same way all the time. If you do 1,000 takeoffs, you will get 1,000 of exactly the same takeoff.”

    Embraer, London adds, has already started flight testing, with the aim to get it approved by aviation authorities in 2025, before introducing it from select airports.

  18. The lake is dwelling to a large variety of wildlife including alligators, giant-mouth bass, herons, cranes, white-tailed deer, manatees, river otters, and bobcats.

  19. Page is survived by a daughter-in-legislation, Lisa Johnson Web page, and a grandson, Grady Jonathan Page, all of Washington, D.C.

  20. You probably have a nicely-stocked craft drawer, you seemingly won’t have to spend a dime pulling together this quick and easy wreath.

  21. Given Wisconsin’s robust agricultural tradition, it isn’t surprising that a large part of the state’s manufacturing sector deals with food processing.

  22. 4-63. In stability operations and support operations, depth extends affect in time, house, objective, and assets to have an effect on the surroundings and circumstances.

  23. Joint doctrine discusses the assignment and obligations related to theater operational areas.

  24. The primary ever certified passive home was constructed almost two decades in the past, creating a legacy of some 30,000 projects in all corners of the globe.

  25. This 43-room, 35,000-sq.-foot house in Ellison Bay, Wisconsin was bought in 2016 for $2.7 million, slightly down for the value of $20 million paid for it in 2005.

  26. AgustinBougs表示:

    https://indianpharmdelivery.com/# top 10 online pharmacy in india
    india pharmacy

  27. “It think that is just a little extra touching.

  28. RichardThini表示:

    mexican online pharmacies prescription drugs: mexican pharmaceuticals online – purple pharmacy mexico price list

  29. Half-hour hearth resistance may be achieved by way of autoclaved, aerated concrete blocks cemented between the flanges and tied to the web of rolled sections.

發佈留言

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