learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
Hope you can help.
I have an AJAX script as below...
Then, in a loop from a recordset, I have links as below (also to display returned value)...
The link calls the AJAX and passes the ID from that loop to a php page as below...
With me so far???
OK... here's the hitch..
This only works once with the first link I click, regardless of how many rows are in the recordset. Also the innerHTML "AjaxOutput" always returns to the first iteration.
Do I somehow have to create multiple AJAX functions for each row and if so, how can I do this in a loop?
Hope this makes sense.
Rich
I have an AJAX script as below...
Code:
var ajaxDownrate;//create ajax variable
//main funtion to create XMLhttp request from event call
function ajaxDownrateCall(str)//str is value from field
{
//try various browsers
try{
// Opera 8.0+, Firefox, Safari
ajaxDownrate = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxDownrate = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxDownrate = 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_fail.php";
url=url+"?downlink="+str;//add value and assign to link
ajaxDownrate.onreadystatechange=downStateChanged;//function to receive data from server
ajaxDownrate.open("GET",url,true);
ajaxDownrate.send(null);
}
function downStateChanged()
{
if (ajaxDownrate.readyState==4)//check if response is ready from server
{
var result = ajaxDownrate.responseText;//retreive data from server
//document.getElementById("AjaxOutput").value=result;//specify output in field
document.getElementById("AjaxOutput").innerHTML = result;//specify output in div
}
}
Then, in a loop from a recordset, I have links as below (also to display returned value)...
HTML:
<div class="contentbox" id="AjaxOutput">
<div class="link"><a href="javascript:ajaxDownrateCall(<?php echo $row_fulltext_images['ID'];?>)">Fail</a></div>
<div class="box"><?php echo $row_fulltext_images['ID'];?><?php //echo $row_fulltext_images['WIDTH']; ?>x<?php //echo $row_fulltext_images['HEIGHT']; ?></div>
</div>
The link calls the AJAX and passes the ID from that loop to a php page as below...
PHP:
require_once('../Connections/discountdomains.php');
include('../includes/function_sanitise_sql_string.php');
mysql_select_db($database_discountdomains, $discountdomains) or die('Could not select db. ');
$ajaxdownlink=$_GET["downlink"];
$ajaxdownlink=GetSQLValueString($ajaxdownlink,"int");
echo $ajaxdownlink;
$updatequery = "UPDATE images SET SUIT = -10, THUMBOK = 0 WHERE ID = '".$ajaxdownlink."' LIMIT 1";
$updateresult = mysql_query($updatequery) or die('Could not update.');
//clear thumbnail
@unlink('../thumbs/'.$ajaxdownlink.'.jpg')
With me so far???
OK... here's the hitch..
This only works once with the first link I click, regardless of how many rows are in the recordset. Also the innerHTML "AjaxOutput" always returns to the first iteration.
Do I somehow have to create multiple AJAX functions for each row and if so, how can I do this in a loop?
Hope this makes sense.
Rich