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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥50 需要加权最小二乘Python代码
      • ¥15 hanzi-writer生成的svg外有一层div,修改div宽高影响的是画布大小,字体在不同视口下完全不相同。我想要让字体跟画布同比例大小该怎么实现?
      • ¥15 Java集合多对一问题集
      • ¥20 PowerShell如何操作记事本?
      • ¥15 intel网卡固件降级失败
      • ¥20 html使用模型的问题
      • ¥15 这些怎么解题啊来个人
      • ¥15 h5套壳IOS Cordova依赖找不到导致编译失败
      • ¥15 分组密码算法misty1的子密钥生成算法c++实现
      • ¥15 vscode的一些报错,希望可以得到解决