简体   繁体   中英

My PHP script for ajax is returning blank value

sbms.php

<?php
header('Access-Control-Allow-Origin: *');
if(isset($_POST['signup']))
{
    $id = $_POST['val'];
    echo $id;
}
?>

index.html

<form>
      <label class="item-input">
      <span class="input-label">ID</span>
      <input type="text" id="cid">
      </label>
      <label class="item-input">
      <button class="button button-block button-positive" id="signup">Submit</button>
      </label>
      </form>
      <div class="card">
      <div class="item item-text-wrap">
        <p id="res"></p>
      </div>
   </form>

ajax script:-

$(document).ready(function(){
$('#signup').click(function(){
    var data = $('#cid').val();
    $.ajax({
        type : "POST",
        data : val,
        url : 'http://127.0.0.1/ionic/sbms.php',
        crossDomain : true,
        success : function  (data) {
            alert(data);
        }
    });
});
});

I am just trying to a dummy response from the server but the response I get is totally blank. I am not able to figure out the problem

You're not sending a signup value, you're just sending in an unnamed value so your PHP script is not entering the if condition. Try changing your ajax call to this:

$.ajax({
    type : "POST",
    data : { val: val, signup: true }
    url : 'http://127.0.0.1/ionic/sbms.php',
    crossDomain : true,
    success : function  (data) {
        alert(data);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM