Hello, I need help in AJAX...can anyone help me?
Function in javascript file which is creating object and below is the function which upon clicking on the rating stars..being called and open ajax.php with querystring.
var http = createRequestObject();
var displayRating = '';
var currentId = '';
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
ro = new XMLHttpRequest();
}
return ro;
}
function updateRating(obj, rating) {
var id = obj.title;
var fullId = obj.id;
var idName = fullId.substr(0, fullId.indexOf('_'));
var totalRating = rating;
currentId = idName;
http.open('post', 'ajax.php?id='+id+'&idName='+idName);
alert('ajax.php?id='+id+'&idName='+idName);
[b]//working fine until here... id and idName is returning the correct variables which I am passing, when I pass the same variables manually, database updated very fine but this script doesn't work and says object as no properties in another function. that function is of changeout. Below![/b]
http.onreadystatechange = handleResponse;
http.send(null);
}
function changeover(obj, rating) {
var imageName = obj.src;
[b]//Here it says that object has no properties![/b]
var id = obj.title;
var index = imageName.lastIndexOf('/');
var filename = imageName.substring(index+1);
var fullId = obj.id;
var idName = fullId.substr(0, fullId.indexOf('_'));
var totalRating = rating;
for(i=0; i<id; i++) {
var num = i+1;
if (num%2 == 0) {
document.getElementById(idName+'_'+num).src = 'include/rating/orating/_even1.jpg';
}
else {
document.getElementById(idName+'_'+num).src = 'include/rating/orating/_odd1.jpg';
}
}
}
ajax.php is here!
if(isset($_GET['idName'])) {
$toneid=$_GET['idName'];
$add=$_GET["id"];
// add the rating to the field/database
$db = mysql_connect("localhost", "","");
mysql_select_db("stardatabase",$db);
$query = "select rating, rated from tones where toneid='$toneid'";
$result = mysql_query($query);
while ($myrow = mysql_fetch_array($result))
{
$rating= $myrow["rating"];
$rated= $myrow["rated"];
//echo $rated;
}
$rating=$rating+$add;
//echo "$rating<br>";
$rated=$rated+1;
//echo "$rated<br>";
$query = "UPDATE tones SET rating=$rating where toneid='$toneid'";
$result = mysql_query($query);
$query = "UPDATE tones SET rated=$rated where toneid='$toneid'";
$result = mysql_query($query);
// display the current(new) rating
$rating=$rating/$rated;
echo $rating;
}
when I give manually values to ajax.php like ajax.php?id=5&idName=6 it works fine and database get updated but through ajax its not working!
P.S these file are from http://www.phpclasses.org/browse/package/3309.html
An Ajax based class by sudhir to update ratings through star system!