Handling jquery ajax form submit with php

I recently struggled with jQuery and Ajax, trying to submit forms with them. I have a very simple form with a username and password field, as well as a submit button. It is assumed that the form should consist in the fact that after the form is submitted, the information will be sent by Ajax to the php file, which will then add the specified form values ​​to the database. What I'm struggling with is how to get 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, how can I get a dataString from this with php?

+3
source share
2 answers

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:

enter image description here

Thus, I assume that you cannot get your data in javascript.

. "GET". php :

echo $_SERVER["REQUEST_URI"];

?:)

+1

POST ( Ajax, -ajax). PHP $_POST.

, check.php:

<?php 
print_r($_POST);
?>

Ajax alert().

0

All Articles