Recently I've been struggling with Jquery and Ajax while trying to submit forms with them. I have a very simple form with a username field and password field as well as a submit button. What the form is supposed to do is that once the form is submitted the info would be sent by Ajax to a php file which then adds the said form values to a database. What I am struggling with is how to get the values from Ajax to php. Here is my code:
$('#form').submit(function(){
var username = $('#username').val();
var password = $('#password').val();
var dataString = 'uname=' + username + '&passw=' + password;
$.ajax({
type: "POST",
url:'check.php',
data: dataString,
success: function(data){
alert(data);//only for testing purposes
}
});
What eludes me is how can I get the dataString from this with php?
PHP file:
<?php
print_r($_POST);
?>
jQuery part:
var dataString = 'uname=555';
$.ajax({
type: "POST",
url:'check.php',
data: dataString,
success: function(data){
alert(data);//only for testing purposes
}
});
brings me:

So my only guess would be that you are failing to fetch your data in javascript.
One more idea. Replace the type with "GET". Then in php file write a line:
echo $_SERVER["REQUEST_URI"];
What does it give you in the alert box? :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With