4

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.

2
  • Use a callback rather than polling. The asynchronous nature of AJAX (the first "A" stands for "asynchronous") means callbacks are at its heart, supported by the onreadystatechange listener for XMLHttpRequest. Is send defined by a third party library or your own? Commented Mar 3, 2010 at 14:14
  • We had to write our own library for the JavaScript. was lot of experimenting and searching around how to accomplish the heart of AJAX functions thanks for the tip I'll have a look on the callbacks any tips on where to find good info on this? Commented Mar 3, 2010 at 14:32

1 Answer 1

18
setTimeout(testIfToegevoegd(),500);

should be

 setTimeout(testIfToegevoegd,500);

you have to pass the function itself, not its result

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.