weixin_33743661 2018-06-21 04:29 采纳率: 0%
浏览 10

使用ajax传递数据

var i = 3;
$("#add_driver").click(function () {
  $("#add_driver_section").replaceWith(-- -- --);
  i++;
  $.ajax({
    type: 'GET',
    url: 'step-3.php',
    data: {
      c: i
    },
    success: function (response) {
      alert(response.status);
    }
  });
});

this is my first page

<?php
if(isset($_GET['c'])){
    echo $_GET['c'];
}else echo 'error';
?>

this the second page. i need to pass the value of i from the first page to the php script in the second using ajax.

I get this error in the #result element

Notice: Undefined index: c in C:\xampp\htdocs\try\carenquery\step-3.php on line 5

what am i doing wrong?


HTML

<div class="wrap-input100 validate-input bg1 rs1-wrap-input100">
  <div class="contact100-form-btn" id="add_driver">
    <span>
      Add another Driver <i class="fa fa-long-arrow-right m-l-7" aria-hidden="true"></i>
    </span> 
  </div> 
</div>
  • 写回答

1条回答 默认 最新

  • weixin_33682719 2018-06-21 05:17
    关注

    Try this.

    var i = 3;
    $("#add_driver").click(function () {
      $("#add_driver_section").replaceWith(-- -- --);
      i++;
      $.get('step-3.php',{c:i},function(x){$('#result').html(x)});
    });
    

    and this is for step-3.php

    <?php
        if(isset($_GET['c'])){
            echo $_GET['c'];
        }else echo 'Get Nothing';
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿