How to pass jquery variables to another php file
Clash Royale CLAN TAG#URR8PPP
How to pass jquery variables to another php file
I have the code below for Java Script on getwifi1.php
$(function()
$('#wifi-avail').on('click', 'td', function()); //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
$name1
$name2
What have you tried to debug this? Have you inspected your browser's developer console to see whether the data is passed to the backend properly?
– Nico Haase
Aug 10 at 11:24
Your code should work. In the php try var_dump($_POST) to see if you have the variables. Also, in JS, before the ajax call console.log the user and pass to make sure they have info.
– Majid Akbari
Aug 10 at 13:57
1 Answer
1
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);
);
http://api.jquery.com/jquery.ajax/
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How do you know
$name1
and$name2
are empty?– kerbholz
Aug 10 at 11:10