Improved task in case this fails.
Added elif to check if the task has failed.
Implemeneted cancel_task function to allow the user cancel tasks running
Added else if statement to control if the task has failed and stop the
ajax request.