jeudi 14 juin 2018

How to return the count from a php loop in controller to javascript?

I have a process that imports >1M records from a txt file. I want to be able to return to the user a count of records processed as it crunches away. My suspicion is js is the right way. I have this loop in my php controller which is working via ajax http call, my question is how can I return a count for each loop to update my js view?

while (($line = fgets($handle)) !== false) {
            //dd($line);
            $cpc = new Cpc();
            $cpc->street = substr($line, 34, 30);
            $cpc->stype = substr($line, 64, 6);
            $cpc->city = substr($line, 112, 30);
            $cpc->province = substr($line, 2, 2);
            $cpc->postal = substr($line, 167, 6);
            $cpc->save();
            $i++;
            $totRecords = $i;

            JavaScript::put([  //trying put here but no luck
                'totRecords' => $totRecords
            ]);
        }

This is a Laravel 5.3 project using Angular 2.0.

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire