AJAX XMLHTTP Request
I have created a mozilla extension which is a button located on the browser. This button has a javascript which when clicked should send a XMLHTTLP request. I want to use a local HTML file which I have created in the URL field of it. When I use it I still can't view that HTML page. Why is that so? The code goes like this:
CustomButton = {
1: function ()
{
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 && 开发者_C百科xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/sample.html",true);
xmlhttp.send();
}
}
The sample.html
file is located in the htdocs
folder of xampp.
Accessing local files with XMLHttpRequest is not allowed for security reasons.
精彩评论