[jQuery] XHR to other domains
Hi,
I'd like to embedd in an XUL extension XmlHTTPRequests.
I've tested at the moment with apache in the browser the ajax
script and it works fine.
However,when I try to fetch XML data from another host than mine
I get some error like this
Error: uncaught exception: Permission denied to call method
XMLHttpRequest.open
In the javascript error console I get this.
I've tried to do the same thing with jQuery and there were no problems
with this while using jquery,why doesn't XHR just work like jquery does
here?
What am I doing wrong here in XHR ?
The code for XHR for this:
1
2 <html>
3 <head>
4 <script type="text/javascript">
5 document.write(' s ');
6 function timer() {
7 var objXMLHTTP = new XMLHttpRequest();
8 var objXML;
9 objXMLHTTP.onreadystatechange = asyncHandler;
10 objXMLHTTP.open('GET', 'http://192.168.1.3/ajax/get_data.pl', true);
11 //objXMLHTTP.open('GET','http://www.xmlfiles.com/examples/cd_catalog.xml',true);
12 objXMLHTTP.setRequestHeader('Content-Type','text/xml');
13 objXMLHTTP.send(null);
14 function asyncHandler() {
15 if(objXMLHTTP.readyState == 4)
16 objXML = objXMLHTTP.responseXML;
17 if(objXML) {
18 setVal(objXML.getElementsByTagName("time")[0].childNodes[0].nodeValue);
19 }
20 }
21
22
23 setTimeout('timer();',2000);
24 };
25 function setVal(msg) {
26 if( document.getElementById('txtbox') ) { //first it does not exist that's why it doesn't find it
27 document.getElementById('txtbox').value = msg ;
28 }
29 }
30 function conVal(msg) {
31 if( document.getElementById('txtbox') ) { //first it does not exist that's why it doesn't find it
32 document.getElementById('txtbox').value += msg ;
33 }
34
35 }
36 timer();
37
38 </script>
39 </head>
40 <body>
41 <textarea id="txtbox" cols="20" rows="10" ></textarea>
42 </body>
43 </html>
The JQUERY code for this :
<html>
<head>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('body').append("
");
jQuery.refresh = function () {
$.post('get_data.pl',{},
function(xml) {
$("p").remove(".tst");
$('body').append('<p class="tst">Url:'+ $('url',xml).text() + '');
$('body').append('<p class="tst">Description:'+ $('description',xml).text() + '');
$('body').append('<p class="tst">Time:'+ $('time',xml).text() + '');
setTimeout("jQuery.refresh()",500);
}
);
};
jQuery.refresh();
});
</script>
<style type="text/css">
a.test { font-weight: bold; }
a.norma {}
</style>
</head>
<body>
<a href="http://google.com/">I give a message when you leave</a>
<a href="http://yahoo.com/" class="hideme">Click me to hide!</a>
<a href="http://microsoft.com/">I'm a normal link</a>
</body>
</html>
--
Stefan Petrea
homepage : http://perlhobby.googlecode.com/
mobile phone : +40732070179