donglan6967 2013-09-25 02:06
浏览 54
已采纳

PHP的jQuery / AJAX执行无法正常工作

I am trying to use jQuery/AJAX to run a PHP file on a server. This PHP simply adds a row with some constants to a database. Here is my code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Submit Application</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
    $.get("http://.../submitApp.php");
}
</script>

</head>

<body>
<form id="form1" name="form1" method="post" action="javascript:doSomething()">
  <p>
    <label for="programName"></label>
    <input type="text" name="programName" id="programName" />
  </p>
  <p>
    <label for="greQuant"></label>
    <input type="text" name="greQuant" id="greQuant" />
  </p>
  <p>
    <label for="greVerbal"></label>
    <input type="text" name="greVerbal" id="greVerbal" />
  </p>
  <p>
    <input type="submit" name="submitApp" id="submitApp" value="Submit" />
  </p>
</form>
</body>
</html>

Upon pressing the submit button on the above form, nothing seems to happen. I should mention I am running this locally via DreamWeaver. I know for a fact that the code is reaching the JavaScript method and that the PHP code is functional. Anyone know what's wrong?

  • 写回答

1条回答 默认 最新

  • dtmbc1606 2013-09-25 02:26
    关注

    Use POST instead of GET to do this work.

    function doSomething() {
       var programName = $('#programName').val();
       var greQuant = $('#greQuant').val();
       var greVerbal = $('#greVerbal').val();
       $.ajax({
          type: "POST",
          url: "submitApp.php", //URL that you call
          data: { programName: programName, greQuant:greQuant, greVerbal:greVerbal } //var in post: var from js
       }).done(function(msg) {
          alert(msg);//change to something to indicate action
       }
    });
    

    and with your php, handle like this

    <?php
    
    $programName = $_POST['programName'];
    $greQuant = $_POST['greQuant'];
    $greVerbal = $_POST['greVerbal'];
    
    //do something important
    
    ?>
    

    this is just a simple example, you need apply some security to this php code

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题