Hi. I've a mainform2.php where I want to display the result in table or div or any html element for the time being and I coded for the click event of the button to do this.
Here is my code for mainform2.php for button.click event.
and here is my show-cart.php table
When I click the button
so I get the following error in the Debugger Tab of the browser.
Paused on Exception
TypeError: cannot use 'in' operator to search for "length" in "[{"item_id":"1",..."
Though I've not used any "in" operator anywhere. The jquery.js file is also red in the Debugger Tab.
I've search so many questions on Google but their answers are not relevant to me.
Guide me please, Thanks
Here is my code for mainform2.php for button.click event.
Code:
$(document).ready(function(){
function loadData(){
//alert("hello");
$.ajax({
url: "show-cart.php",
type: "POST",
success: function(data){
//console.log(data);
$.each(data, function(key, value){
$("#cart-table").append('<tr><td>' + value.item_id + '</td></tr>');
$("#showme").append(value.item_name);
});
}
});
}
$(document).ready(function(){
$("#btnClear").on("click", function(){
$("#order-form").trigger("reset");
loadData();
});
});
});
Code:
<?php
$conn = mysqli_connect("localhost", "root", "", "chargha") or die ("Your Connection Failed");
$sql = "SELECT items.item_id, items.item_name, items.item_unit_price, cart.order_qty, cart.order_price, cart.order_of, cart.order_instructions, cart.token_id
from cart LEFT JOIN items ON cart.item_id = items.item_id";
$query = mysqli_query($conn, $sql);
$output = mysqli_fetch_all($query, MYSQLI_ASSOC); //It transform the array into associative one. mysqli_asssoc, num, both
echo json_encode($output);
?>
Code:
input type="button"
Quote:
Paused on Exception
TypeError: cannot use 'in' operator to search for "length" in "[{"item_id":"1",..."
I've search so many questions on Google but their answers are not relevant to me.
Guide me please, Thanks