Reputation: 491
I have a logging page and I wanted to send the logging details in json format to the checkuser.php file which is a other page in the web site. checkUser.php file will create a new window. What is the best way to do this ? if possible please give me some example.
Upvotes: 0
Views: 419
Reputation: 2310
$("#myform").submit(function( e ) {
e.preventDefault();
$.ajax({
url: "blabla.com/api",
type: 'POST',
contentType: 'application/json',
data: JSON.stringify( { key: val } ) // <-------- HERE IS YOUR JSON
}).done(function() {
console.log('hooray!');
});
});
Upvotes: 1
Reputation: 229
Suppose you have a login form as login.php with html form controls txtLogin and txtPassword and a Submit button. Once the user submits the form it would post data onto checkuser.php You can write the following code that can push data in JSON format
$login = $_POST['txtLogin'];
$password = $_POST['txtPassword'];
$userArray = array('login'=>$login,'password'=>$password);
$json_array = json_encode($userArray);
Upvotes: 0