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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵