0

The script works just fine in IE, problems occur in FF.

<script language="JavaScript" type="text/javascript"> 
  var counter = 0; 
  window.onload = ajaxFunction; 
      function ajaxFunction(nr){ 
        var ajaxRequest; 
   try{ 
      // Opera 8.0+, Firefox, Safari 
      ajaxRequest = new XMLHttpRequest(); 
   } catch (e){ 
      // Internet Explorer Browsers 
      try{ 
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
      } catch (e) { 
         try{ 
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
         } catch (e){ 
            // Something went wrong 
            return false; 
         } 
      } 
   } 

function feedback(){ 
    if(ajaxRequest.readyState==4){ 
                  var ajaxDisplay = document.getElementById('ajaxDiv'); 
           ajaxDisplay.innerHTML = ajaxRequest.responseText; 
          } 
     } 

if(!nr || nr==null){                                //problem seems to be somewhere 
          counter = counter + 3;               //in this part, FF doesn't somehow get the value "nr" 
          }                                   //FF skips that part completely and reads counter = 0 
          else counter = counter + nr;               

     var url = "homeproov.php"; 
     var leht = "?counter=" + counter; 
    ajaxRequest.open("GET", url+leht, true); 
    ajaxRequest.send(null); 
    ajaxRequest.onreadystatechange = feedback; 
} 
</script>

The lower part goes to the <body> section

<div style='float:left;margin-top:25px;'><a href="javascript: void(0)" onclick="ajaxFunction(-3)" ><img src='navimg.png' /></a></div> 
  <div id='ajaxDiv' style='float:left;'>Results</div> 
  <div style='float:right;margin-top:25px;'><a href="javascript: void(0)" onclick="ajaxFunction(3)" ><img src='navimg2.png' /></a></div>

PHP code is following:

$show = 3; 
$counter = $_GET['counter']; 
$max = 'limit '.$counter.','.$show; 

$tulemus=mysql_query("SELECT film.nimi,film.aasta,zanr.zanr,zanr.sisestuskp,zanr.cover FROM film,zanr 
 WHERE film.nimi=zanr.nimi ORDER BY nimi $max") or die(mysql_error());

mysql_error says :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[object Event],3' at line 3

Anybody knows how can i get this to work in FF?:-/

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ffs
0

To initiate a global variable, remove the var in front of counter.
Firefox is respecting the scope of the var, by not making it a global variable, while IE is making it a global variable.
The mysql error is from not having an argument sent to the php script.
I also would put in some error checking to ensure the counter GET variable is actually sent (an if with an else echo, to keep it simple, or a thrown error...).
Hope that helps!

0

Thank you for your reply.
I changed the "if(!nr || nr==null){" part to "if(counter==0){" and it works now.
The solution was easier than i thought.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.