JS functions not working while loading html using Ajax
When I load an asp file (Main_Page_1.asp), in the click event of a button there is a function invocation is not working. There is I am stuck in.
for eg:-
Main_Page_1.asp
<head><script type="text/javascript" src="JsFile.js"></script>
<script type="text/javascript">
function buttonClicked ()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest(); }
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("ajaxResult").innerHTML='';
document.getElementById("ajaxResult").innerHTML= xmlHttp.responseText;
}
}
xmlHttp.open("GET","Result_Page_2.asp" ,true);
xmlHttp.send(null);
开发者_StackOverflow中文版}
</script>
</head>
<body >
<div id=”ajaxResult”></div><button onclick="buttonClicked()">click me</button></body>
Result_Page_2.asp
<head><script type="text/javascript" src="JsFile.js"></script>
</head>
<body >
<a rel="HSTIP" herf=”Details_page.asp”>Details</a><div style="width: 178px" id="HSTIP"
class="MTStyle" >My Mouse Tool Tip</div></body>
This is the asp files (Result_Page_2.asp) I am trying to load using ajax. Now buttonClicked() residing in JsFile.js are not executed while the event happens.
In the JsFile.js file is used to load mouse tip window in the mouse over of “Details” hyperlink
Please let me know where things go wrong.
I'm having a little trouble understanding exactly what your problem is, but what may be useful for you to know is that script tags injected directly using innerHTML
are not processed by the browser. If you need to load additional Javascript asynchronously you should look into jquery or a similar javascript library that extends AJAX functionality to get around this problem.
Result_Page_2.asp
<head><script type="text/javascript" src="JsFile.js"></script>
</head>
<body >
<a rel="HSTIP" herf=”Details_page.asp”>Details</a><div style="width: 178px" id="HSTIP"
class="MTStyle" >My Mouse Tool Tip</div><body>
your end tag of has no "/"
It seems as if your 2nd page will return the entire page including the < head > and < body > tags. What does JsFile.js contain?
What I could recommend you to do is use Firebug Add-On to analyze the response that you are getting back from the 2nd page. From there, you can see exactly what you are getting back.
精彩评论