First, I realize there are a lot of other similar posts. I have read through many, and I have still not been able to this it to work. That being said.....I have a 2 dimensional javascript object that is created dynamically. I am trying to pass it to PHP so I can save insert it into a MySQL table. It looks like the easiest way to do this is with an Ajax post. Here is my javascript:
var jsonString = JSON.stringify(TableData);
$.ajax({
type: 'POST',
url: 'submit.php',
data: jsonString,
success: function(){
alert("OK");
}
});
I always get the success alert so I don't think the problem is there. Here is my PHP file.
<?php
$servername = "localhost";
$username = "SME";
$password = "mypass";
$db = "p3";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $db);
if (!$conn) {
die("Could not connect to database");
} else echo "hey hey";
$data = json_decode("jsonString");
print $data;
?>
I am not really sure what I am doing wrong. Both of the files are in the same folder so I don't think it's a URL problem. Any help would be appreciated.
$data = json_decode($_POST);echo / printan array ( at least in a meaningful way) tryprint_r(),var_dump()orvar_export()next time..