Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript too much recursion?

I'm trying to make a script that automatically starts uploading after the data has been enter in the database(I need the autoId that the database makes to upload the file).

When I run the javascript the scripts runs the php file but it fails calling the other php to upload the file.

too much recursion
setTimeout(testIfToegevoegd(),500); 

the script that gives the error

send("/projects/backend/nieuwDeeltaak.php",'deeltaakNaam='+f.deeltaaknaam.value+'&beschrijving='+
                        f.beschrijving.value+'&startDatum='+f.startDatum.value+'&eindDatum='+f.eindDatum.value
                        +'&deeltaakLeider='+f.leiderID.value+'&projectID='+f.projectID.value,id);

                    function testIfToegevoegd(){

                        if(document.getElementById('resultaat').innerHTML == "<b>De deeltaak werd toegevoegd</b>"){
                            //stop met testen + upload file 

                            document.getElementById('nieuwDeeltaak').target = 'upload_target';
                            document.forms["nieuwDeeltaak"].submit()
                        }else{
                            setTimeout(testIfToegevoegd(),500);
                        }

                    }

                    testIfToegevoegd();

sorry for the dutch names we have to use them it is a school project.

when I click the button that calls all this for a second time (after the error) it works fine.

like image 267
Ken Avatar asked Dec 03 '22 06:12

Ken


1 Answers

setTimeout(testIfToegevoegd(),500);

should be

 setTimeout(testIfToegevoegd,500);

you have to pass the function itself, not its result

like image 144
user187291 Avatar answered Dec 10 '22 22:12

user187291