How to pass an array of objects trough a jquery $.post?
Posted
by majc
on Stack Overflow
See other posts from Stack Overflow
or by majc
Published on 2010-05-24T23:30:17Z
Indexed on
2010/05/24
23:31 UTC
Read the original article
Hit count: 184
Hi,
I want to pass the result of a query trough a $.post.
function GetAllTasks()
{
$sql = "select t.id as task_id,
description,
createdat,
createdby,
max_requests,
max_duration,
j.name as job_name
from darkfuture.tasks t, darkfuture.jobs j
where t.job_id = j.id";
$sqlresult = mysql_query($sql)
or die("The list of works failed: ".mysql_error($this->con));
$result = array();
while($row = mysql_fetch_assoc($sqlresult))
{
$task = new TasksResult();
$task->id = $row["task_id"];
$task->description = $row["description"];
$task->createdat = $row["createdat"];
$task->createdby = $row["createdby"];
$task->max_requests = $row["max_requests"];
$task->max_duration = $row["max_duration"];
$task->job_id = $row["job_name"];
array_push($result, $task);
}
mysql_free_result($sqlresult);
return $result;
}
Here is how i call it:
$tasksDB = new TasksDB();
$tasks = $tasksDB->GetAllTasks();
Now i want to pass $tasks through here:
$.post("views/insert_tasks.php",{'tasks[]': $tasks}, function(data)
{
});
I know this {'tasks[]': $tasks} it's wrong but i don't know how to do it right. Some help will be appreciated. Thanks in advance!
© Stack Overflow or respective owner