Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax Value Not Transmitting To PHP
    primarykey
    data
    text
    <p>I have this Star Rating system right. When you click on a star it should pass a value into the function. Then using AJAX it posts it to an external PHP file. The only problem is that when it gets to the PHP file it comes as null or no value.</p> <p>I will try to echo the $_POST['vote'] variable in an alert box using AJAX and it is blank so it doesn't come back as "NULL" or "0" it's just nothing. I'm not sure where I'm losing the value because I can track it all the way to the send() function. Anyone see a problem?</p> <p><strong>HTML:</strong> </p> <pre><code>&lt;style type="text/css"&gt; #container{margin: 10px auto;width: 500px;height: 300px;background-color: gray;} #starContainer{padding-top:20px;margin:0 auto;width:150px;} .box{height:28px;width:30px;float:left;position:relative;z-index:5;cursor:pointer;} .star{background-image:url('emptyStar.png');background-repeat:no-repeat;} .starHover{background-image:url('goldStar.png');background-repeat:no-repeat;} #voteBar{float:left;height:28px;background-color:#dbd923;position:relative;top:-28px;z-index:1;} &lt;/style&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('.box').hover( // Handles the mouseover function() { $(this).prevAll().andSelf().addClass('starHover'); }, // Handles the mouseout function() { $(this).prevAll().andSelf().removeClass('starHover'); } ); }); function Cast(vote) { if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { alert(xmlhttp.responseText); var json = JSON.parse(xmlhttp.responseText); } } xmlhttp.open("POST", "process.php", true); xmlhttp.send('vote=' + vote); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;center&gt; &lt;div id="starContainer"&gt; &lt;div class="box star" onclick="Cast(1)"&gt;&lt;/div&gt; &lt;div class="box star" onclick="Cast(2)"&gt;&lt;/div&gt; &lt;div class="box star" onclick="Cast(3)"&gt;&lt;/div&gt; &lt;div class="box star" onclick="Cast(4)"&gt;&lt;/div&gt; &lt;div class="box star" onclick="Cast(5)"&gt;&lt;/div&gt; &lt;div id="voteBar"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/center&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>PHP:</strong></p> <pre><code>&lt;?php $vote = $_POST['vote']; $totalVoteValue = 0; $amtVotes = 1; $width = (($totalVoteValue + (($vote - $totalVoteValue) / $amtVotes)) / 5) * 150; echo $width; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload