Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 运行php的第1部分,然后单击(通过jquery)运行第二部分_Javascript_Php_Jquery - Fatal编程技术网

Javascript 运行php的第1部分,然后单击(通过jquery)运行第二部分

Javascript 运行php的第1部分,然后单击(通过jquery)运行第二部分,javascript,php,jquery,Javascript,Php,Jquery,我正在做一个在线实验,人们需要点击一个图表,按提交,点击一个新的图表,提交,等等。单击值需要注册并保存在服务器上的文件中 我的html文件由不同图表的不同div组成。单击SubmitwithChart1将隐藏该div并显示下一个div 在我当前的html/jquery/php组合中,我遇到了一个问题:对于div1,保存来自div2的点击的代码也会运行。因此,单击chart1 y=16、submit和chart2 y=52后,我的txt文件如下所示: 根据图1图表位置的坐标:9.088588588

我正在做一个在线实验,人们需要点击一个图表,按提交,点击一个新的图表,提交,等等。单击值需要注册并保存在服务器上的文件中

我的html文件由不同图表的不同div组成。单击SubmitwithChart1将隐藏该div并显示下一个div

在我当前的html/jquery/php组合中,我遇到了一个问题:对于div1,保存来自div2的点击的代码也会运行。因此,单击chart1 y=16、submit和chart2 y=52后,我的txt文件如下所示:

根据图1图表位置的坐标:9.088588588588589-16.032534246575345

根据图2图表位置的坐标:-

根据图1图表位置的坐标:-

坐标符合图2的图表位置:8.998498498498499-51.8681506849151

因此,即使只加载并单击了第一个div,php也会为这两个div运行“log”操作。我能把这个弄得更整洁些吗?我可以手动删除空系列,但下一个版本应该有15个图表,这将是一个很大的工作

如果我在这里发布JS,它就不会显示得很清楚,所以我将其复制粘贴到JSFIDLE中:

我的php代码: “savetofile.php”
// get your data from the client
$xax = $_POST['xax'];
$yax = $_POST['yax'];

$out;

// validate $xax and $yax

// save your variables to a file
$result = file_put_contents("log.txt", PHP_EOL ."Coordinates according to chart location for plot1 : " . $xax . " - " . $yax, FILE_APPEND);

// tell the user what happened
if ($result !== FALSE) {
  $out = [ "message" => "success!", "status" => 200];
}
else {
  $out = [ "message" => "error saving file", "status" => 500];
}

// send stuff back to the client
echo json_encode($out);


// get your data from the client
$xax2 = $_POST['xax2'];
$yax2 = $_POST['yax2'];

$out;

// validate $xax and $yax

// save your variables to a file
$result = file_put_contents("log.txt", PHP_EOL ."Coordinates according to chart location for plot2 : " . $xax2 . " - " . $yax2, FILE_APPEND);

// tell the user what happened
if ($result !== FALSE) {
  $out = [ "message" => "success!", "status" => 200];
}
else {
  $out = [ "message" => "error saving file", "status" => 500];
}

// send stuff back to the client
echo json_encode($out);
exit();

最后一点:我有点犹豫是否发布这个,因为我知道我的编码很混乱。我所知道的一切都是在过去五周自学的,我对php的知识非常有限。代码也从为本地托管的实验设计发展到了在线实验。所以请不要拒绝我:

看起来您的代码工作正常。在plot1之后,没有什么可以停止脚本,因此它将继续并处理plot2。如果您希望它是AJAX,请将它放在单独的脚本中,并通过AJAX调用它,或者先传递一些查询参数并对其进行测试。谢谢您的回复!我明白你的意思,但我坚持用实际的解决办法。如果在plot1之后结束脚本,它将不会为第二个逻辑图重新运行。我只是使用另一个php文件吗?然后我会得到15个php文件。。看起来他们应该是一个更简单的解决方案,但我不知道怎么做