[eluser]kilishan[/eluser]
[quote author="daK" date="1305603786"]Can someone elucidate me this piece of code from ToDo tutorial final script, at the end where developer introduces the ajax call
Code:
public function delete()
{
$id = $this->uri->segment(5);
$this->todo_model->delete($id);
echo 'true'; // <----- THESE TWO LINES
die();
}
Why are we echoing TRUE (and what happens if FALSE) and then halting the script by die()ing?[/quote]
Since this is an AJAX call, jQuery is expecting some form of confirmation in it's $.post() call. This just allows for a check on the success state of the PHP script. However, in the final version of this script, this is not actually necessary. I had started doing error checking in the javascript, but then decided that really wasn't necessary for this tutorial.