if (isset($input['category_id'])) {
$categoryId = $input['category_id'];
if($categoryId > 0){
$products = ExecuteRows("SELECT * FROM pos_product WHERE category_id = '$categoryId' ORDER BY product_name ASC");
}
else {
// Prepare the SQL statement
$products = ExecuteRows("SELECT * FROM pos_product ORDER BY product_name ASC");
}
WriteJson($products);
works and i got json data response . But the issue is that i get bunch of html codes and white space with the response and this is crashing my code.
[{"product_id":66,"category_id":4,"product_name":"Assorted peppersoup","product_image":"null.png","product_cost":"0.00","product_price":"5000.00","product_status":"Available"},{"product_id":5,"category_id":2,"product_name":"Jollof Rice","product_image":"food-removebg-preview.png","product_cost":"0.00","product_price":"1000.00","product_status":"Available"},{"product_id":3,"category_id":1,"product_name":"Malt","product_image":"soda-removebg-preview(2).png","product_cost":"0.00","product_price":"1000.00","product_status":"Available"},{"product_id":4,"category_id":1,"product_name":"Malt2","product_image":"soda-removebg-preview.png","product_cost":"0.00","product_price":"1000.00","product_status":"Available"},{"product_id":65,"category_id":3,"product_name":"Peppered Goat meat","product_image":"null.png","product_cost":"0.00","product_price":"4000.00","product_status":"Available"},{"product_id":2,"category_id":2,"product_name":"Pizza","product_image":"food-removebg-preview(2).png","product_cost":"0.00","product_price":"345.00","product_status":"Available"},{"product_id":1,"category_id":2,"product_name":"Rice","product_image":"menu-removebg-preview.png","product_cost":"0.00","product_price":"1000.00","product_status":"Available"},{"product_id":67,"category_id":2,"product_name":"Rice2","product_image":"null.png","product_cost":"0.00","product_price":"3000.00","product_status":"Available"}]
<!DOCTYPE html>
<html data-bs-theme="light">
<head>
<title>POS</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/vintopos/css/select2.min.css?v=24.16.8">
<link rel="stylesheet" href="/vintopos/css/select2-bootstrap5.min.css?v=24.16.8">
<link rel="stylesheet" href="/vintopos/plugins/fontawesome-free/css/all.min.css?v=24.16.8">
<link rel="stylesheet" href="/vintopos/adminlte3/css/adminlte.min.css?v=24.16.8">
<link rel="stylesheet" href="/vintopos/css/vintopos.min.css?v=24.16.8">
<script data-pace-options='{"ajax":{"trackMethods":["GET","POST"],"ignoreURLs":["\/session?"]},"eventLag":false}' src="/vintopos/js/pace.js?v=24.16.8"></script>
<!-- Single quotes for data-pace-options -->
<script src="/vintopos/js/ewcore.min.js?v=
console error : sales:793 Fetch error: SyntaxError: Unexpected non-whitespace character after JSON at position 1405 (line 1 column 1406)