Progress of Ajax

Is there any way to have feedback from an ajax submit which inserts records into a database?

I have a CGridView with checkboxes and each of the records need to be imported using a database driver that takes ~2 mins per record. I think it would be beneficial to display which records have been inserted.

an ajax request is a http request after all, so you have no way to return data back while the request is running (you can only do it when it ends).

In order to accomplish what you need, you can so something like:

// javascript code.

var ids=[1,2,3,4,5];//you'd take these from your selected rows in the grid, this is just an example.

var i=0;


function callThisRecursiveFunction(){

   if(ids.length == 0){

     // the recursive function done all the items in the queue, so we need to stop and tell the user we're done.




   var requestId=ids.splice(0,1);



         $("#some-id").html("Action #"+i+" completed");





Your Yii controller action should be smth like:

public function actionProcess($id){



     // this is an invalid request

     echo json_encode(array('result'=>'error'));



   // do processing here

   echo json_encode(array('result'=>'success'));



These are big lines, but you get the point…i hope :)

Fantastic! It seems so obvious now.

Keep up the good work!