views:

49

answers:

2

document.ready() not triggered after ajax request in IE but work a charm in FF and chrome. I have two files. First file(test.jsp) just has a submit button. onclick it loads from struts the second file(result.jsp). . the two files are

test.jsp

    <html>
<head>
<script type="text/javascript" src="/js/jquery-1.2.6.min.js"/></script>
<script type="text/javascript" src="/js/api.js"></script>

<script type="text/javascript">
$(document).ready(function(){
    $("#test").click(function()
    {
        var path = "/TestAjax.do"
        $.get(path,function(data)
        {
           document.write(data);

        });
    });
});
</script>
</head>
<body>
<div><h3>Hello World</h3><br/>
<input type="button" id="test" value="submit"/>
</div>
</body>
</html>

result.jsp

    <html>
<head>
<script type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    alert("success");
});


</script>
</head>
<body>
<div><h3>result</h3><br/>
<!--input type="button" id="test" value="submit"/-->
</div>
</body>
</html>

when result.jsp loads alert("success"); is called.... This works well in FF and chrome. But not in IE. the alert doesnt pop up. Displays error as Object expected i document.ready() line. But works if we refresh the page....

Any help will be appreciated...

+1  A: 

When I do an ajax-request I always add a random number/string as parameter to the ajax url. This almost always fixed my IE related errors because it forces IE to load reload the page and not use one from the cache.

wose
A: 

@ wose

thanx a lot for ur suggestion. i hope cache is not a problem as i have tried dlearing the cache....

Praveen