Jump to content

Ajax open new page


kvnirvana

Recommended Posts

New.php is a page generated from another page. On New.php the user can choose to do a rating.

If they click rating they get to Getuser.php, where there is a starrating, which works fine, but

when the user clicks on the star rating bar it redirects to a blank page, which it didn’t do before, I used ajax. When a user clicked on the rating stars it said ‘thank you for voting’. I would like to know how to get this same function using ajax, or at least how to redirect to another page after clicking on the rating stars. I’m thinking it has something to do with this line

xmlhttp=new XMLHttpRequest();

but honestly I don’t have a clue :=) Please help me. Thanks

 

 

 

 

this is the ajax part from New.php

<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("kom").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("kom").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str+"&navn=<?php echo $_GET['navn']; ?>"+"&pr=<?php echo $_GET['pr']; ?>"+"&id=<?php echo $_GET['id']; ?>",true);
xmlhttp.send("");
}
</script>

And this is the page Getuser.php where the star rating is

<?php                                                                                                   
                                                                                                        
                                                                                                        
                                                                                                        
$sql = "select * from beha WHERE navn='" . $_GET['navn'] . "'and  pr='" . $_GET['q'] . "'"; 
  //run query                                                                    
   $result = conn($sql);                                                         
                                                                                 
   if (!$result){ die("No results due to database error.<br>".mysql_error());  } 
     if (mysql_num_rows($result)==0)          
     {                                        
       echo "No Results found!";              
     }else{                                   
                                              
                                              
    while ($rows= mysql_fetch_array($result)) 
        {                             
    	echo "<TR>";	                    
                                      
     echo rating_bar($rows['id'],'6');
      echo "</TR>";
      
          }  
             
             
             
      }      ?>

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.