Welcome Guest, Not a member yet? Register   Sign In
The Javascript function doesn't work
#1

[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'>&nbsp;</td>\n";
   echo "<td>&lt;input type='button' name='update' value='Ändern' &gt;&lt;/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 &Auml;nderungen erkannt.";
   }
  } else {
   echo "Keine &Auml;nderungen vorgenommen.";
  }
}

Where is the problem?
#2

[eluser]TheFuzzy0ne[/eluser]
If you're getting a 404 error, and you're not explicitly using show_404() somewhere other than your controller, then the problem is most likely with your controller - which you haven't posted your code for.
#3

[eluser]yuro[/eluser]
Code:
Thats the Controller:

function ajax_wkorb() {
  $this->load->model('Order_model', '', TRUE);
  
  return $this->Order_model->updateWarenkorbAjax($this->input->post('ids'));
}
#4

[eluser]TheFuzzy0ne[/eluser]
Is error reporting enabled, and have you tried accessing the URL by typing it into your address bar?
#5

[eluser]yuro[/eluser]
sorry that is the code:

Code:
function ajax_wkorb() {
  $this->Order_model->updateWarenkorbAjax($this->input->post('ids'));
}

but he also doesn't work.

when I click on "update", he should give me a text that the records are updated via Ajax function.
#6

[eluser]TheFuzzy0ne[/eluser]
Is error reporting enabled, and have you tried accessing the URL by typing it into your address bar?
#7

[eluser]yuro[/eluser]
What do you mean exactly?
#8

[eluser]Jan_1[/eluser]
what do you get if you point your browser to "your_url/welcome/ajax_wkorb".
#9

[eluser]yuro[/eluser]
Hej Jan,

I get the message from the order model:

Code:
else {
    echo "Keine &Auml;nderungen erkannt.";
   }
#10

[eluser]kostyak[/eluser]
Hi!
It seems to be ok. But I can't see how you stick 'onclick' to your button? Can you revise it and check if by clicking on the button only js script executes and doesn't execute form action?




Theme © iAndrew 2016 - Forum software by © MyBB