duanji1043 2013-11-20 17:22
浏览 27
已采纳

PHP不起作用

I have a code that looks like this:

jQuery.post("test1send.php", { browName : browser, timeCan: testTimeCanvas , timeSVG: testTimeSVG });

window.location.href = 'http://localhost/start/prosteTest2.html';

.php file looks like:

<?php
 $browName = $_POST['browName'];
 $timeCan = $_POST['timeCan'];
 $timeSVG = $_POST['timeSVG'];

    if($browName=='Opera'){
    $rowsCount = count(file('Data\Test1\Test1Opera.csv'));
    $fp = fopen('Data\Test1\Test1Opera.csv', 'a');
    fwrite($fp, $rowsCount);
    fwrite($fp, ',');
    fwrite($fp, $timeCan);
    fwrite($fp, ',');
    fwrite($fp, $timeSVG);
    fwrite($fp, "
");
    fclose($fp);
    }else if($browName=='Firefox'){
    $rowsCount = count(file('Data\Test1\Test1Firefox.csv'));
    $fp = fopen('Data\Test1\Test1Firefox.csv', 'a');
    fwrite($fp, $rowsCount);
    fwrite($fp, ',');
    fwrite($fp, $timeCan);
    fwrite($fp, ',');
    fwrite($fp, $timeSVG);
    fwrite($fp, "
");
    fclose($fp);
    }
 ?>

It should send variables to php and load next page. PHP should save variables to .csv file but it does not work. If there is no "window.location.href" it works fine but when there is command to go to next page PHP does nothing. Does it need some delay to do PHP first and then go to next page??

  • 写回答

2条回答 默认 最新

  • doy51723 2013-11-20 17:26
    关注

    Put the window.location.href in the success callback of the post - http://api.jquery.com/jQuery.post/

    jQuery.post("test1send.php", { browName : browser, timeCan: testTimeCanvas , timeSVG: testTimeSVG }, function(){ window.location.href = 'http://localhost/start/prosteTest2.html'; });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法