1

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

4
  • Do I need to specify action too? Commented May 2, 2016 at 19:07
  • I want to make it in AJAX Commented May 2, 2016 at 19:08
  • Also, did you enable php error logs ? Commented May 2, 2016 at 19:08
  • I was marking it as the right answer but was asked to waitt ill 10 minutes Commented May 2, 2016 at 19:22

1 Answer 1

4

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);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.