The below is posting in dev console as POST: 404. I'm guessing my php is not correct. What am I doing wrong here?
On this JS side I'm doing:
........
user = JSON.stringify(user); // updated Data, want to push to db table blob column
pushData ();
function pushData (){
const ajax = $.ajax({
method: 'POST',
url: `./Settings.php`,
data: {obj_json: JSON.stringify(user) },
dataType: "json",
success: function(result) {
//Write your code here
console.log("data posted?");
}
});
}
.....
/Settings.php (the class used has valid db connection, my obj_json is the column that is set to blob in db table). I am not really sure what to do with $obj
class Settingz extends \myApp\Data
{
public function insertBlob($obj, $last_update) {
$obj = $_POST['obj_json'];
$sql = "INSERT INTO MY_TABLE(last_update,obj_json) VALUES(:last_update,:obj_json)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindParam(':last_update', $last_update);
$stmt->bindParam(':obj_json', $blob, PDO::PARAM_LOB);
return $stmt->execute();
}
}
:obj_jsonin VALUES, but binding with:prefs_json.objs_jsonwith an "s". Handling files is usually done with$_FILESin a form when done in pure PHP instead of$_POSTand with an proper enctype. If this is JS or OOP related, I'm not the guy for this.