weixin_33735676 2018-05-06 20:32 采纳率: 0%
浏览 23

AJAX未执行PHP脚本

I am attempting to write an application that interacts with a library and gets values from it, and I can't seem to figure out how to get a php script to execute when a button is clicked.

Index.html

Chapter: <input type="text" name="chapter"><br>
Section: <input type="text" name="section"><br>
Problem: <input type="text" name="problem"><br>
<input type="button" class="button" name="insert" value="Get Input" 
onClick="doStuff()"/>

<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
function doStuff()
{
var v1 = document.getElementById('chapter').value;
var v2 = document.getElementById('section').value;
var v3 = document.getElementById('problem').value;

 $.ajax({
 type: "POST",
 url: "get-data.php",
 data: {chapter:v1,section:v2,problem:v3},
 success: function(data) {
      alert(data);
  }

  });
}
</script>

get-data.php

<?php

    function doit()
    {
        $chapter=$_GET['chapter'];
        $section=$_GET['section'];
        $problem=$_GET['problem'];
        $command = "python proc.py init $chapter $section $problem";
        $output = exec($command);
        echo $output; 
    }
    doit()
    ?>

the python script is confirmed to be working, and the php script is confirmed to be working when executed by using <form action="get-data.php"> but it always redirects to a simple page where the output is echo to.

  • 写回答

3条回答 默认 最新

  • weixin_33720186 2018-05-06 20:35
    关注

    You should receive values in php page by using $_POST not $_GET, because in ajax request that you wrote you are using type = "POST".

    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序