PHP Function call with AJAX - Update cookie -


i'm trying update cookie in online-store. when amount of specific product in store updated, cookie has updated , reload page.

i'm trying onchange event jquery. coded follows:

$.ajax({             type: 'post',             url: "./dao/winkelwagendao.php",             data: {function: "updateaantal", productid: productid, aantal: aantal},             success: function (data) {                 console.log("succeeded!", data);                 //location.reload(); //to reload page               },             error: function (err) {                 console.log("something went wrong in ajax-request: ", err);             }             });         }); 

this works , logging correct things.

now php-file catch event:

if (isset($_post['function'])) {     $action = $_post['function'];     switch ($action) {         case 'updateaantal' :             echo "\namount change productid: " . $_post['productid'] . " use function: " . $_post['function'] . " set amount to: " . $_post['aantal'];             winkelwagendao::updateaantal($_post['productid']);     } } 

here updateaantal()-function called defined inside php_file. therefore have include php file access getters/setters. (i think there problem here because when include_once './model/winkelwagenitem.php'; gives warning file not found (altough class/class/... correct). when file_exists in code below says file exist (a bit stuck here)

public static function updateaantal($productid) {     if (file_exists('model/winkelwagenitem.php')) {         //echo "\nfile wanted import in winkelwagendao exist!\n<br>";         include_once 'model/winkelwagenitem.php';     } else {         //echo "file wanted import in winkelwagendao not exist!";     }      echo "\nupdateaantal function called";     $array = self::getwinkelwagenitems();      echo $array[0]->getproductid(); //here goes wrong      if (isset($_cookie["winkelwagen"])) { //cookie exists?         $array = self::getwinkelwagenitems();         $index = 0; //positie bijhouden          foreach ($array $product) {             if ($productid == $array[$index]->getproductid()) {                 //echo $productid . " == " . $array[$index]->getproductid();                  $array[$index]->setaantal($_post['aantal']);                 $serializearray = serialize($array);                 setcookie("winkelwagen", $serializearray);                  break; //quit if match             } else {                 $index++;             }         }     } else {         echo "this cookie did not exist";     } }` 

this in console (error @ bottom) :

console logs functions - includes error message

seems can not call ->getproductid() because of include_once() not done right? when include_once gives warning that: no such file in directory, double checked , file exist. says exists when use if (file_exists in php).

source/model/winkelwagenitem -> getters , setters source/dao/winkelwagendao -> updateaantal function 

can me out ? been trying day


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -