Why does it say task is NULL?
I get the AJAX response in firefox.
http://janisrough.dyndns.biz/todo9.html.
Does it have something to do with parsing JSON?
The form handler in php has this last line, print (json_encode($arr_result));
but you can see the response in firefox so it should be parsed and show up in the form
instead it says null.
thanks,
<script type="text/javascript">
function submitForm() {
$.ajax({
type: 'POST',
url: 'form_handler.php',
dataType : 'json' ,
data: $('#taskForm').serialize(),
success: function(response) {
var task= $.parseJSON(response);
var list_start ='<li "class" = "todo-list" >';
var list_end ='</li>';
var checkbx ='<input type="checkbox" id="task" checked="false" />';
var delRow ='<input type="button" value="Delete" class="btnDelete" onclick="deleteRow(this)" />';
alert(row);
$("#main ul li:last").append(
row);
}
});
return false;
}//end submitForm
}
It doesn't matter if I do
task.todo
task[0].todo
or simply
task
I don't get the JSON object parsed. Here is the form_handler.php but I don't think you need it since it is returning the response.
<?php
require("db.php");
//ini_set("max_execution_time",'800');
#error_reporting(E_ALL | E_NOTICE);
error_log("form_handler error",3,"/var/tmp/Janis-Rough.local.err");
//$arry= json_decode($_POST,true);
$task =$_POST['task_todo'];
$date = $_POST['due_date'];
$name = $_POST['todo_name'];
$sql = "INSERT INTO taskos.task(todo, date, name) values('$task','$date','$name') ";
$result = mysql_query($sql);
if ( !$result ) {die( mysql_error() . $sql);}
$sql2 = 'SELECT todo FROM task WHERE todo > "" ';
$result2 = mysql_query($sql2);
if (mysql_fetch_assoc($result2) == 0) {
echo "All tasks have been completed";
exit;
}
$arr_result = array();
if ( !$result2 ) {die("Invalid query" . mysql_error() . $sql );}
while($result_of_result2 = mysql_fetch_assoc($result2))
{
$arr_result[] = $result_of_result2;
}
print (json_encode($arr_result));
?>