PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Mon Aug 10, 2020 2:03 pm

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 
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' >
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>";

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="

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

function ajaxFunction(a, b){
        var ajaxRequest;  // The variable that makes Ajax possible!
                // Opera 8.0+, Firefox, Safari
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                // Internet Explorer Browsers
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                                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;"GET", "actrating.php" + queryString, true);

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... :(

PostPosted: Mon Feb 14, 2011 8:01 pm 
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?

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 8 guests

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