Jump to content

[SOLVED] Ajax not working in Firefox only?


garethhall

Recommended Posts

Hi I have this very simple ajax page and It just won't work in firefox. When I check the XHR response in firebug I get the expected result in this case "test". I don't get way it's not working all the other main browsers seems to work fine it's just firefox? Anyone know why?

 

Holding page ("books.php")

<script type="text/javascript" src="ajax/js/myBooks.js"></script>
</head>

<body id="myAccount" onload="getMyBooks()">

<div id="container">

    <!--Head and nav-->        
   		  <?php include('includes/header.php');?>
    <!--Account nav-->        
   		  <?php include('includes/accountNav.php');?>

<div id="main_content"> <!-- main content to be displayed -->
<div id="main_header">
My Books
</div>

<div id="contentArea"> <!-- div to hold all content inside the  -->
<div class="clear"></div>

<div id="myBookLibrary"></div>

<div class="clear"></div>


</div>
<div id="main_content_footer"></div>
</div>

    <!--Footer-->        
   		  <?php include('includes/footer.php');?>

	  </div> <!-- end container div -->
          
</body>

 

Ajax page ("mybook.js")

var xmlHttp
var url="ajax/myBooks.php?"; 
function getMyBooks(){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
	alert("Browser does not support HTTP Request");
	return;
}
var qstr;
xmlHttp.onreadystatechange=myBookResults;
xmlHttp.open("POST",url,false);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(qstr);
}

function myBookResults(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	document.getElementById("myBookLibrary").innerHTML=xmlHttp.responseText;
};
};
function GetXmlHttpObject(){
var xmlHttp=null;
try{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}catch (e){
	// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	};
};
return xmlHttp;
};

 

PHP page ("myBooks.php")

<?php
echo "test";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.