So I'm still a newbie when it comes to javascript and php. I have a problem:
from javascript, I am viewing the package barcode using a barcode reader. I am sending this to a PHP file using ajax, which builds an object and should return it to javascript code.
I'm doing it:
function LoadPackage(ScannedCode) {
var res;
console.time("Load package " + ScannedCode);
$.ajax({
type: "POST",
url: "ajax/3gmodule_inventory_ajax/getPackage.php",
data: "packageSerial=" + ScannedCode,
cache: false,
async: false
}).success(function(result) {
res = $.parseJSON(result);
});
console.timeEnd("Load package " + ScannedCode);
return res;
}
Php file:
<?php
include_once "../../init.php";
$packageSerial = $_POST["packageSerial"];
$package = tbProductPackage::getInstanceByPackageSerial($packageSerial, $db);
return json_encode($package);
?>
I am 100% sure that my object is correctly built. I did var_dump of my $ package object and everything is fine with it. However, trying to return it to javascript, I tried a bunch of different things, nothing works.
$ .parseJSON (result); seems to be giving me this error:
Uncaught SyntaxError: Unexpected end of JSON input
I also tried using serialize (), but I get an error:
Uncaught exception 'PDOException' with message 'You cannot serialize or unserialize PDO instances'
Basically, my database is in my object, I assume that I can not serialize it ...
?