MasonWolf
asked on
How do I read an HTML page into a javascript string variable?
I have a dynamically created page with a very small amount of html on it. I can read it into a javascript through php to initialize it, but while the user is viewing the page, the dynamic link may need to change. Basically, I need a way to read the new page into a javascript string, and then from there I can use it for what I need it to do.
Is there a class or function that's supported by most browsers that will allow me to do this?
As an alternate solution, I could read in all the potential page iterations at the time the page is pulled from the server and save them to javascript array variables. But I'm hoping someone at ee knows a better way.
Is there a class or function that's supported by most browsers that will allow me to do this?
As an alternate solution, I could read in all the potential page iterations at the time the page is pulled from the server and save them to javascript array variables. But I'm hoping someone at ee knows a better way.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah! Ok, I gotcha. The script in question is on the same domain as the one I'm calling in the functional page, but I was using a different server to test. Thanks guys.
Your welcome! So the EE URL was just for posting here. And here I thought you had some script to get EE question info. :)
I'm glad I could help. Thanks for the grade, the points and the fun question.
bol
I'm glad I could help. Thanks for the grade, the points and the fun question.
bol
The line:
xmlHttp.setRequestHeader(' Content-Ty pe', 'application/x-www-form-ur lencoded') ;
is required if you want to use
xmlHttp.send(querystring);
Sorry, there was a typo in the original.
xmlHttp.setRequestHeader('
is required if you want to use
xmlHttp.send(querystring);
Sorry, there was a typo in the original.
ASKER
Here's the test script.
<script type="text/javascript">
function GetXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.X
}
return objXMLHttp;
}
function getHTML(querystring)
{
var xmlHttp;
var returnString;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="https://www.experts-exchange.com/questions/22740977/How-do-I-read-an-HTML-page-into-a-javascript-string-variable.html";
xmlHttp.onreadystatechange
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="compl
{
//document.getElementById(
returnString = xmlHttp.responseText;
}
};
xmlHttp.open("GET",url+que
xmlHttp.send(null);
return returnString;
}
document.write(getHTML('?c
</script>
The error I received back was: "uncaught exception: Permission denied to call method XMLHttpRequest.open"