PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 13, 2018 12:48 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem with ajax script
PostPosted: Sat Feb 05, 2011 9:31 am 
Offline
Forum Commoner

Joined: Mon Jul 05, 2010 9:03 am
Posts: 29
Hi...I am new to ajax and currently developing a website where users are supposed to rate posts. I want to avoid page refreshing when a rate is given. To do that, the php code is

Syntax: [ Download ] [ Hide ]
<form name='rate' >
<?php
echo "<input type='image' src='actstar.gif'  name='rate1' id='button1' value='1' title='Value rating 1' onclick='ajaxFunction(this.value, $varid)'/>";
      echo "<label for='label2'></label>";
echo "<input type='image' src='actstar.gif'  name='rate2' id='button2' value='2' title='Value rating 2' onclick='ajaxFunction(this.value, $varid)'/>";
echo "<label for='label3'></label>";
echo "<input type='image' src='actstar.gif'  name='rate3' id='button3' value='3' title='Value rating 3' onclick='ajaxFunction(this.value, $varid)'/>";
echo "<label for='label4'></label>";
echo "<input type='image' src='actstar.gif'  name='rate4' id='button4' value='4' title='Value rating 4' onclick='ajaxFunction(this.value, $varid)'/>";
echo "<label for='label5'></label>";
echo "<input type='image' src='actstar.gif'  name='rate5' id='button5' value='5' title='Value rating 5' onclick='ajaxFunction(this.value, $varid)'/>";
echo "<label for='label6'></label>";
?>
</form>
 


And the ajax code is

Syntax: [ Download ] [ Hide ]
<script type="text/javascript" src="/home/walknsh1/public_html/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"
></script>

<script language="javascript" type="text/javascript">



function ajaxFunction(a, b){
        var ajaxRequest;  // The variable that makes Ajax possible!
       
        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
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }

ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
                // document.rate.time.value = ajaxRequest.responseText;
        }
}
        var queryString = "?val=" + a + "id=" + b;
        ajaxRequest.open("GET", "actrating.php" + queryString, true);
        ajaxRequest.send(null);
       
}
</script>
 


Now the problem is that nothing is happening. I have done the coding as per w3schools tutorials but here actrating.php is not being called on hitting the button.
Whats the issue?? M I missing somegthing?? Plzz Help... :(


Top
 Profile  
 
PostPosted: Mon Feb 14, 2011 8:01 pm 
Offline
Forum Contributor
User avatar

Joined: Thu Oct 20, 2005 7:01 pm
Posts: 127
Is there a reason you are not using the JQuery ajax function since you are already including it?
http://api.jquery.com/category/ajax/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group