[eluser]yuro[/eluser]
Hello,
I have a JavaScript function that will be executed when you click the button "update" button and store the new value in a session.
But whenever I change the number in my cart and click update, he shows me a 404 error.
I work with Prototype & scriptaculous.
In my template I embedded the source:
Code:
View:
[removed][removed]
[removed][removed]
[removed][removed]
In a another view:
echo "<tr valign='top'>\n";
echo "<td colspan='3'> </td>\n";
echo "<td><input type='button' name='update' value='Ändern' ></td>\n";
echo "</tr>\n";
Code:
Thats the function when you click on the button "update"
customtools.js:
function jsUpdateWarenkorb() {
var parameter_string = '';
allNodes = document.getElementsByClassName("process");
for(i=0; i<allNodes.length; i++) {
var tempid = allNodes[i].id;
var temp = new Array;
temp = tempid.split("_");
var real_id = temp[2];
var real_value = allNodes[i].value;
parameter_string += real_id + ':' + real_value + ',';
}
var params = 'ids='+parameter_string;
var ajax = new Ajax.Updater(
'ajax_msg','/welcome/ajax_wkorb', {method:'post',parameters:params,onComplete:showMessage}
);
}
function showMessage(req) {
$('ajax_msg')[removed] = req.responseText;
location.reload(true);
}
Code:
Thats the Function in the Order_model:
function updateWarenkorbAjax($idlist) {
$warenkorb = $_SESSION['warenkorb'];
$datensaetze = explode(',', $idlist);
$updated = 0;
$summe = $_SESSION['summe'];
if(count($datensaetze)) {
foreach($datensaetze as $datensatz) {
if(strlen($datensatz)) {
$felder = explode(":", $datensatz);
$id = $felder[0];
$wk = $felder[1];
if($wk > 0 && $wk != $warenkorb[$id]['count']) {
$warenkorb[$id]['count'] = $wk;
$updated++;
} elseif($wk == 0) {
unset($warenkorb[$id]);
$updated++;
}
}
}
if($updated) {
$summe = 0;
foreach($warenkorb as $id => $produkt) {
$summe += $produkt['preis'] * $produkt['count'];
}
$_SESSION['summe'] = $summe;
$_SESSION['warenkorb'] = $warenkorb;
echo $updated . " Datensätze aktualisiert.";
} else {
echo "Keine Änderungen erkannt.";
}
} else {
echo "Keine Änderungen vorgenommen.";
}
}
Where is the problem?