使用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>

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';
?>