Asynchronous surprises

Hi Clifton,
This has probably more to do with php than Powerpac but I would be grateful for your help. I need to save a file with several hundred characters on the server and then empty the array that was used to create the file to start a new project. The return from the server is an integer corresponding to the number of characters. I imagined that if I waited for the callback from the server before emptying the array there would be no problem. Surprisingly the array gets emptied before the file is saved! I can't understand how this happens. Any suggestions please?
I am now using a 'time-switch' like this:
if (isNaN(e.data))
{
alert("ERROR:" + "\n" + e.data);
}
else
{
if (sharedActions.newProject == true)
{
var fct = function()
{
sharedActions.newProject1();
}
setTimeout(fct, 500);
}
}
but I'm not convinced it will always solve the problem.
John
PS here is the php file I'm using:
<?php
$serverPath=$_SERVER['DOCUMENT_ROOT'].'/programs';
if (isset($_POST['endPath']))
{
$endPath=$_POST['endPath'];
if (isset($_POST['mydata'])) {
echo file_put_contents($serverPath.$endPath, $_POST['mydata']);
// If the return value is more than 0, presumably the file has been written.
}
else
{
echo 'notSet';
}
}
else
{
echo 'notSet';
}
UPDATE
I have now added the LOCK_EX parameter to the file_put_contents line in the php file and I think it does the trick but could you confirm this please?
?>
This has probably more to do with php than Powerpac but I would be grateful for your help. I need to save a file with several hundred characters on the server and then empty the array that was used to create the file to start a new project. The return from the server is an integer corresponding to the number of characters. I imagined that if I waited for the callback from the server before emptying the array there would be no problem. Surprisingly the array gets emptied before the file is saved! I can't understand how this happens. Any suggestions please?
I am now using a 'time-switch' like this:
if (isNaN(e.data))
{
alert("ERROR:" + "\n" + e.data);
}
else
{
if (sharedActions.newProject == true)
{
var fct = function()
{
sharedActions.newProject1();
}
setTimeout(fct, 500);
}
}
but I'm not convinced it will always solve the problem.
John
PS here is the php file I'm using:
<?php
$serverPath=$_SERVER['DOCUMENT_ROOT'].'/programs';
if (isset($_POST['endPath']))
{
$endPath=$_POST['endPath'];
if (isset($_POST['mydata'])) {
echo file_put_contents($serverPath.$endPath, $_POST['mydata']);
// If the return value is more than 0, presumably the file has been written.
}
else
{
echo 'notSet';
}
}
else
{
echo 'notSet';
}
UPDATE
I have now added the LOCK_EX parameter to the file_put_contents line in the php file and I think it does the trick but could you confirm this please?
?>