Java123 Posted July 10, 2011 Share Posted July 10, 2011 Hi. I'm new to AJAX and JavaScript. This code wil change the content of the text after clicking on the "Change Content" button. I tried to run this code(from W3) on my PC and received this error: Error On Page. Line 22 Char 1, Error: Access is denied, Code: 0. UR file:///H:/Advanced%20HTML%20-%week3/index1.html. This happens after I click on "Change Content". This is my file, onmy PC that isn't shared with anyone. What's happening? Thanks In Advance. <html><head><script type="text/javascript">function loadXMLDoc(){var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","ajax_info.txt",true);xmlhttp.send();}</script></head><body><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc()">Change Content</button></body></html> Link to comment Share on other sites More sharing options...
Ingolme Posted July 11, 2011 Share Posted July 11, 2011 Have you tried with a different browser? Internet Explorer doesn't work with AJAX properly when run from the local machine. Link to comment Share on other sites More sharing options...
Java123 Posted July 11, 2011 Author Share Posted July 11, 2011 Thanks for responding. I tried it w/Firefox 3.6.16 and did not receive the "access denied" error. BUT I also did not get my intended results. When I click on the "Change Content" button nothing happens.(??) Link to comment Share on other sites More sharing options...
Ingolme Posted July 11, 2011 Share Posted July 11, 2011 Look at the browser's error console to see what's failing. Link to comment Share on other sites More sharing options...
birbal Posted July 11, 2011 Share Posted July 11, 2011 are you opening the file from filesystem directly? or using localhost from the browser? Link to comment Share on other sites More sharing options...
Java123 Posted July 11, 2011 Author Share Posted July 11, 2011 Thanks for responding. I tried it w/Firefox 3.6.16 and did not receive the "access denied" error. BUT I also did not get my intended results. When I click on the "Change Content" button nothing happens.(??) Link to comment Share on other sites More sharing options...
Java123 Posted July 11, 2011 Author Share Posted July 11, 2011 Thanks for responding. I tried it w/Firefox 3.6.16 and did not receive the "access denied" error. BUT I also did not get my intended results. When I click on the "Change Content" button nothing happens.(??) Ingolme: Look at the browser's error console to see what's failing. My Response: How do I do that?birbal are you opening the file from filesystem directly? or using localhost from the browser? My Response:I'm using localhost from the browser. Link to comment Share on other sites More sharing options...
Java123 Posted July 11, 2011 Author Share Posted July 11, 2011 are you opening the file from filesystem directly? or using localhost from the browser?[birbal are you opening the file from filesystem directly? or using localhost from the browser? My Response:I'm using localhost from the browser Link to comment Share on other sites More sharing options...
Java123 Posted July 11, 2011 Author Share Posted July 11, 2011 Look at the browser's error console to see what's failing.[birbal are you opening the file from filesystem directly? or using localhost from the browser? My Response:I'm using localhost from the browser Link to comment Share on other sites More sharing options...
thescientist Posted July 11, 2011 Share Posted July 11, 2011 the error console is built into your web browser. google on how to open it for your browser. Usually a lot of debugging and logging is used when creating websites with Javascript functionality. Learning to read and use the error console will help you identify problems that much faster.Based on the code you provided though, I don't know what you are expecting to happen, as you have not defined any sort of status checking of the request, or defined a method for handling the response. You are only making the request. Have you read through all the AJAX tutorials?http://www.w3schools.com/ajax/default.asp Link to comment Share on other sites More sharing options...
Java123 Posted July 12, 2011 Author Share Posted July 12, 2011 the error console is built into your web browser. google on how to open it for your browser. Usually a lot of debugging and logging is used when creating websites with Javascript functionality. Learning to read and use the error console will help you identify problems that much faster.Based on the code you provided though, I don't know what you are expecting to happen, as you have not defined any sort of status checking of the request, or defined a method for handling the response. You are only making the request. Have you read through all the AJAX tutorials?http://www.w3schools.com/ajax/default.asp Link to comment Share on other sites More sharing options...
Java123 Posted July 12, 2011 Author Share Posted July 12, 2011 I'm stuyding the AJAX tutorial at this time, and also learning about my browser console. Thank everyone so much for the tips, ideas, and help. Link to comment Share on other sites More sharing options...
Java123 Posted July 17, 2011 Author Share Posted July 17, 2011 Thank you everyone for your responses. My problem was caused by not having my ".txt" file in with my ".html" file. Once I put them in the same folder, the code worked as designed. Again thank you. I learned a lot.Java123 Hi. I'm new to AJAX and JavaScript. This code wil change the content of the text after clicking on the "Change Content" button. I tried to run this code(from W3) on my PC and received this error: Error On Page. Line 22 Char 1, Error: Access is denied, Code: 0. UR file:///H:/Advanced%20HTML%20-%week3/index1.html. This happens after I click on "Change Content". This is my file, onmy PC that isn't shared with anyone. What's happening? Thanks In Advance.<html><head><script type="text/javascript">function loadXMLDoc(){var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","ajax_info.txt",true);xmlhttp.send();}</script></head><body><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc()">Change Content</button></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.