Notice: Undefined index: PHP and Ajax

3

I'm trying to send a form, but when sending the page does not reload, for that I'm using ajax and then to save them PHP, but I have the following problem, he says Notice: Undefined index: mail in C: \ xampp \ htdocs \ send \ formsubs.php on line 2

HTML CODE

<form class="form-subs" id="form-sub"  method="post" onsubmit="return subs();">
          <input type="email"  id="correo" name="correo"  placeholder="&#xf0e0; Correo electronico"><br>
          <input type="submit" name="submit" id="send1" value="Enviar">
        </form>

JavaScript CODE

  function subs() {
    var correo = document.getElementById('correo').value;
    //var fdata = 'correo='+correo;
    $.ajax({
      type:'post',
      url:'../send/formsubs.php',
      data: 'correo='+correo,
      success:function(msgsub) {
        $("#send1").hide(function() {
          $("#load2").fadeIn(function() {
            $("#load2").delay(1000).fadeOut(function() {
              $("#sub-res").html(msgsub);
            });
          });
        });
      }
    });
    return false;
  }

AND THE PHP CODE STILL NOT FINISHED

<?php
  $correo = $_REQUEST['correo'];
  echo $correo;
 ?>

If someone could help me I would be very grateful !!!

    
asked by Eugeni Bejan 20.05.2016 в 10:39
source

1 answer

1

I recommend sending the data by POST.

function subs() {
    var correo = document.getElementById('correo').value;
    $.ajax({
      type:'post',
      url:'../send/formsubs.php',
      data: {correo: correo},
      success:function(msgsub) {
        $("#send1").hide(function() {
          $("#load2").fadeIn(function() {
            $("#load2").delay(1000).fadeOut(function() {
              $("#sub-res").html(msgsub);
            });
          });
        });
      }
    });
    return false;
  }

// PHP

<?php
  $correo = $_POST['correo'];
  echo $correo;
 ?>

To see what you receive by php type var_dump($_POST);

    
answered by 20.05.2016 / 15:31
source