learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
OK - this is weird and I hope I can get some help here.
I have managed to integrate one AJAX call into a page, which uprates an image at database level and then responds with the current rating.
Example page is at http://www.qualityimagesearch.com/view_image.php?img_id=34706
The js in this page is as follows:
Then I have a button with an event call as follows:
The php it calls (with GET variable) is
So far, this works great!! really pleased with that BUT...
I want to do the same with a downrate button.
I have duplicated the javascript ajax but changed all variable names from up**** to down****
The button event calls a different but similar php page, which simply downrates the image.
Now although the call is working with a db update, the responsetext doesn't work with the first call.
Is there an issue outputing to the same div id?
Any help would be appreciated.
All files below
View attachment ajax_downrate.txt
View attachment ajax_uprate.txt
View attachment view_image.txt
I have managed to integrate one AJAX call into a page, which uprates an image at database level and then responds with the current rating.
Example page is at http://www.qualityimagesearch.com/view_image.php?img_id=34706
The js in this page is as follows:
Code:
<script type="text/javascript">
var ajaxUprate;//create ajax variable
//main funtion to create XMLhttp request from event call
function ajaxUprateCall(str)//str is value from field
{
//try various browsers
try{
// Opera 8.0+, Firefox, Safari
ajaxUprate = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxUprate = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxUprate = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser does not support HTTP requests.");
return false;
}
}
}
//specify url to call + variable which will be called using GET
var url="ajax/ajax_uprate.php";
url=url+"?uplink="+str;//add value and assign to link
ajaxUprate.onreadystatechange=stateChanged;//function to receive data from server
ajaxUprate.open("GET",url,true);
ajaxUprate.send(null);
}
function stateChanged()
{
if (ajaxUprate.readyState==4)//check if response is ready from server
{
var result = ajaxUprate.responseText;//retreive data from server
//document.getElementById("AjaxOutput").value=result;//specify output in field
document.getElementById("AjaxOutput").innerHTML = result;//specify output in div
}
}
</script>
Code:
<a href="#nogo" onClick="ajaxUprateCall(<?php echo $row_Image['ID'];?>)"><img src="/images/thumb-up.png" width="50" height="50" border="0" /></a>
PHP:
<?php
require_once('../Connections/discountdomains.php');
mysql_select_db($database_discountdomains, $discountdomains) or die('Could not select db. '.mysql_error());
$ajaxuplink=$_GET["uplink"];
$updatequery = "UPDATE images SET SUIT = SUIT +1 WHERE ID LIKE '".$ajaxuplink."'";
$updateresult = mysql_query($updatequery) or die('Could not update. '.mysql_error());
$selectsql="SELECT * FROM images WHERE ID LIKE '".$ajaxuplink."'";
$selectresult = mysql_query($selectsql) or die('Could not select. '.mysql_error());
while($row_Image = mysql_fetch_array($selectresult))
{
include('../includes/rating.php');//displays small thumb up icons according to rating
}
;
mysql_free_result($selectresult);
?>
I want to do the same with a downrate button.
I have duplicated the javascript ajax but changed all variable names from up**** to down****
The button event calls a different but similar php page, which simply downrates the image.
Now although the call is working with a db update, the responsetext doesn't work with the first call.
Is there an issue outputing to the same div id?
Any help would be appreciated.
All files below
View attachment ajax_downrate.txt
View attachment ajax_uprate.txt
View attachment view_image.txt