Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- session_start();
- if (isset($_SESSION['user'])) {
- $status = 'ERROR';
- $validator = new Validator();
- $validator->add('id:Product_Id', 'required');
- $validator->add('id:Product_Id', 'integer');
- if ($validator->validate($_POST)) {
- try {
- Closet::create([
- 'user_id' => $_SESSION['user']['id'],
- 'product_id' => $_POST['id'],
- ]);
- $status = 'OK';
- } catch (QueryException $e) {
- Log::logError($e->getMessage());
- }
- }
- header('Type-Content: application/json');
- echo json_encode(['status' => $status]);
- }
- else {
- header('Location: pantalladelogin.php');
- }
- <a onclick="addProduct(1)">
- <i class="material-icons">add</i>
- </a>
- function addProduct (id) {
- const formdata = new FormData()
- formdata.append('id', id)
- fetch("/addproduct.php", {
- method: 'post',
- body: formdata
- }).then(function(response) {
- console.log(response)
- return response.text()
- }).then(function(data) {
- console.log(data)
- });
- }
- Response { type: "basic", url: "http://localhost/pantalladelogin.php", redirected: true, status: 200, ok: true, statusText: "OK", headers: Headers, bodyUsed: false }
- var sesion = <?=json_encode($_SESSION['identificadorSesion'])?>;
Add Comment
Please, Sign In to add comment