I am having a great deal of difficulty getting jquery.post() to work properly. Everything seems to be in order but I cannot get my json to display on the screen. I have been working on this for about the last day or so and I am posting here as a last resort. I saw a lot of questions posted on here about ajax.post and a lot of good answers. However most of those Q&As dealt with echoing back simple variables. i.e a single int. Unfortunately, since I am working with an array I don't think the same or similar solutions will work for me. This is a look at the php that is being returned to the first page. We'll refer to this segment as page #2
if (!($stmt = $mysqli->prepare("SELECT id, todos FROM to_do_list WHERE uid =?"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("s", $_SESSION['SESS_ID'])){
echo "Binding param failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()){
echo "Execute failed block 2: (" . $stmt->errno . ") " .$stmt->error;
}
$stmt->bind_result($id, $todos);
if ($stmt->store_result()){
if($stmt->num_rows > 0){
while($stmt->fetch()){
$results[] = array('id' => $id, 'todos' => $todos);
}
echo json_encode($results);
}
Here is a look at the relevant portion of the 1st page, or the calling page:
<div id="content">
</div>
<form title="todosubmitter" id="todoPost" autocomplete="off">
Add To Do:
<br>
<input type="text" name="todo" class="required formStyle error">
<!--<input type="reset" name="submit" value="Submit" onclick="$.post('dbAccessor.php', $('#todoPost').serialize());"> -->
<input type="reset" name="submit" value="Submit" onclick="$.post('dbAccessor.php', $('#todoPost').serialize(), function(data) { $('#content').html(data);}, 'json');">
</form>
No matter what I put in there I cannot get any of my json data to be displayed on the screen. I have tried numerous things. No success.
Also. in before your php doesn't work and isn't returning anything to the 1st page:
[{"id":98,"todos":"asdfa"},{"id":97,"todos":"asdfasdf"},{"id":96,"todos":"adsfasdfadf"},{"id":95,"todos":"asdfasdf"},{"id":94,"todos":"sadfasdf"},{"id":93,"todos":"asdfasdf"},{"id":92,"todos":"adfgadfga"},{"id":91,"todos":"asdfasd"},{"id":90,"todos":"asdfadf"},{"id":89,"todos":"asdfafd"},{"id":88,"todos":"asdf"},{"id":87,"todos":"asdf"},{"id":86,"todos":"asdf"},{"id":85,"todos":"asdf"},{"id":84,"todos":"dfa"},{"id":83,"todos":"asdf"},{"id":82,"todos":"do"},{"id":81,"todos":"asdf"},{"id":80,"todos":"asdf"},{"id":79,"todos":"asdf"}]
Thank you in advance to whom ever can end this mystery for me.