473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to fetch a xml file from different site

Hi, I don't know javasript much. But I know js is the right solution to
my need. I have an xml file (http://example1.com/list.xml) that will be
updated from time to time. I want to give following js code to many
sites (http://example2.com http://example3.com ...) to get newest data
in http://example1.com/list.xml:

code that will be in http://example2.com http://example3.com ... :
// -- code starts here
<script src="http://example1.com/js/fetchsite.js"
type="text/javascript">
</script>
<script type="text/javascript">
ajaxRead('http://example1.com/list.xml');
</script>
// -- code ends here

http://example1.com/js/fetchsite.js :
// -- code starts here
function ajaxRead(file) {
var xmlObj = null;
if(window.XMLHttpRequest) {
xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject) {
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
return;
}
xmlObj.onreadystatechange = function() {
if(xmlObj.readyState == 4){
processXML(xmlObj.responseXML);
}
}
xmlObj.open ('GET', file, true);
xmlObj.send ('');
}
function processXML(obj) {
...
}
// -- code ends here

I googled, it seems that XMLHttpRequest get can't fetch file from a
different site, is that right? Then how can I work around this
limitation?

Mar 16 '06 #1
2 2582


Jesse Woo wrote:
I googled, it seems that XMLHttpRequest get can't fetch file from a
different site, is that right? Then how can I work around this
limitation?


Only on the server, there you can (usually) fetch data from other
servers and that way if your HTML document with the script comes from
http://example.com/ and wants to access e.g. http://example.org/file.xml
then you need to make a request alike
http://example.com/fetch?url=http://...e.org/file.xml
so that your server side script (named 'fetch' in the above example)
accesses the other server example.org to receive the file and return it
to your client-side script.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 16 '06 #2
Jesse Woo said the following on 3/16/2006 4:09 AM:
Hi, I don't know javasript much. But I know js is the right solution to
my need. I have an xml file (http://example1.com/list.xml) that will be
updated from time to time. I want to give following js code to many
sites (http://example2.com http://example3.com ...) to get newest data
in http://example1.com/list.xml:
<snip>
I googled, it seems that XMLHttpRequest get can't fetch file from a
different site, is that right? Then how can I work around this
limitation?


<URL: http://borkweb.com/story/look-ma-cross-domain-scripting >

You do it by creating a script element, dynamically, and setting its src
property to the data returned.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
8
by: Evan Smith | last post by:
During a routine performance check using an event monitor, I discovered a class of query whose performance has me baffled. The monitor captured: SELECT * FROM EWM_CASE fetch first 1 rows only...
16
by: Timm | last post by:
I'm trying to use ASP objects (basically formed and populated based on Web.Config settings) and I want to use them in a different non-asp program with minimal reprogramming. So, my question is how...
19
by: Alan Silver | last post by:
Hello, I have been developing ASP.NET with a text editor so far (better way to learn initially), and have now been trying Visual Web Developer. I want to create a project for an existing site...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
2
by: ckp21082 | last post by:
I want to develop a site in PHP such that user need to enter username and password by validation this username,password i want to fetch data stored in password protected directory so can anybody...
10
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The...
0
by: Rilly | last post by:
Anyone use PowerMovielist here? I have the 0.14 beta version. Do you have a problem where some shows you search for cause the fetch to hang ? I'm pulling my hair out on this.. For example, I search...
0
by: padmaneha | last post by:
Hi Thanks for your response but the query which you gave in my previous post doesnt work. It displays the same cnt for movie reviews and videoreviews Let me explain you in detail As I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.