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
https://forums.phpfreaks.com/topic/172765-solved-ajax-not-working-in-firefox-only/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.