I have the code below for Java Script on getwifi1.php
$(function(){
$('#wifi-avail').on('click', 'td', function(){
var txt;
var user;
var pass = prompt("Please enter your password:", "");
if (pass == null || pass == "") {
txt = "User cancelled the prompt.";
}
user = $(this).html();
$.post(
"newone.php",
{
"username":user,
"password":pass
}
)
alert(user);
alert(pass);
}); //end inner function
}); //end outer function
I want to transfer the value of user and pass to another php file named newone.php in which I have written this code
<?php
$name1 = $_POST['username'];
$name2 = $_POST['password'];
echo $name1;
echo $name2;
?>
but the $name1 and $name2 seems to be empty always. I don't know what I am doing wrong. Can anyone correct my method or write me another code to transfer these two variables from getwifi1.php to newone.php. I have search ajax method which I applied like this but it didn't seem to work either
$.ajax({
method: "post",
url: "newone.php",
data: {username:user, password:pass}
})
ThankYou
See http://api.jquery.com/jquery.ajax/
Type: An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.
I'm not sure, but I think you have to change 'method' to 'type' in your Ajax call. My bad, this is not true and necessary.
This script should be working (and alert any error messages from your newone.php):
$.ajax({
type: 'POST',
url: 'newone.php',
data: {
username: user,
password: password
},
success:function(data){
alert(data);
}
});