douyao7390 2018-08-16 07:44
浏览 260
已采纳

Ajax:功能不起作用

I don't know why my code does not work onclick, but there is no pop up. The AJAX function var phone and id got data, but the AJAX did not. Is there anything wrong with the script? Does the AJAX need a jQuery library?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/core.js"></script>
<script type="text/javascript">
  function clickButton() {
    var phone = document.getElementById('phone').value;
    var id = document.getElementById('id').value;
    $.ajax({
      type: "post",
      url: "userDetaiAjax.php",
      data: {
        'phone': phone,
        'id': id
      },
      cache: false,
      success: function(html) {
        alert('Data Send');
        $('#msg').html(html);
      }
    });
    return false;
  }
</script>
<div class="col">
  <div class="form-group">
      <h6>
        <label>Name :</label>
        <?php echo $name ?>
      </h6>
      <h6>
        <label>Email :</label>
        <?php echo $email ?>
      </h6>
      <input type="" name="phone" id="phone">
      <input type="" name="id" id="id" value="<?php echo $_SESSION[" staff_id "];?>" hidden>
      <h6>
        <label>Phone :</label>
        <?php echo $phone ?>
      </h6>
      <input type="submit" name="aa" value="submit2" onclick="return clickButton();">
    </form>
    <p id="msg"></p>
  </div>
</div>
</div>
</div>

for the url

<?php 
$phone = $_POST['phone'];
$id = $_POST['id'];
echo 'success';
echo $phone;
echo $id;

$a='"USR_ID"';
$b='"phone"';
include 'conn.php';
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

   $query = "update usr_web SET phone=:c1 WHERE usr_id=:c2";

              $stid = oci_parse($conn, $query);

   oci_bind_by_name($stid, ":c1", $phone);
   oci_bind_by_name($stid, ":c2", $id);


                                 $result = oci_execute($stid);
                                 oci_free_statement($stid);
                                 oci_commit($conn);
                                  oci_close($conn);
                            echo $result;

?>
  • 写回答

2条回答 默认 最新

  • down_load1117 2018-08-16 08:10
    关注

    U have error in your console:

    $ is not defined

    Which mean u did not include jquery, so u should add this code after ajax include:

    <script
      src="https://code.jquery.com/jquery-3.3.1.min.js"
      integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
      crossorigin="anonymous"></script>
    

    U can chack your console errors with F12 key in browser and tab Console.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于cpci总线的几个问题,有点迷糊
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化
  • ¥15 搭建QEMU环境运行OP-TEE出现错误
  • ¥15 Minifilter文件保护