J
Jesse Woo
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?
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?