0

I am trying to do a simple name change for a user, which will save their new name into a db. For the ajax call, I am running something like this

var new_name = prompt("Enter your new name" , "Charlie Murphy");

  if(new_name == "" || new_name == null){
    alert("Please actually enter a name");
  }

  else{

    $.ajax({

       url : "./db_scripts/change_name.php",
       type : "POST",
       data : {name : new_name}


    });

My php goes

<?php


$new_name = $_POST['name'];
echo $new_name;

?>

Just to try and get the post to work, but the name is not printing to the browser. I am positive I have my path name right for the db_script, because I have other scripts that are working.

Help

1 Answer 1

3

use the success handler to receive the data from your server page

$.ajax({
       url : "./db_scripts/change_name.php",
       type : "POST",
       data : {name : new_name},
       success: function(data){
         alert(data);
       }
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I had tried the success but was missing a comma after the data. This did it!

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.