Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  65] [ 2]  / answers: 1 / hits: 16374  / 10 Years ago, sat, may 24, 2014, 12:00:00

Well, the problem is not new, as I saw (really surf a lot), but still can not find solution for myself.



Description of problem:




  1. Have local Web server - XAMPP;

  2. Firefox 29.0.1

  3. And trying to send POST with $.ajax



    function checkUser(){
    $.ajax({
    type: 'POST',
    url: 'ajax/checkUser.php',
    data: 'uname='+$(#username).val()+'&pword='+$(#password).val(),
    success: function(){
    someNewFunc();
    },
    });
    };



This function I'm calling with:



$(document).ready(function(){
$(.button.postfix.login).on(click, function(){
if (($(#username).val() != ) && ($(#password).val() != )) {
hide(); <-- hide pop ups about empty field
checkUser();
} else {$(#empty).show();} <-- pop ups
});
});


And here code of page with elements:



<input id=username type=text placeholder=Username />
<input id=password type=password placeholder=Password />

<a class=button postfix login href=#
onclick=event.preventDefault();>Sign in</a>


I guess that data are going out, but the page checkUser.php doesn't get anything.
What am I doing wrong?



P.S. checkUser.php:



<?php
print_r($_POST);
?>


Result - Array ( )



P.P.S. By the way, if POST change to GET it's working, but need to be POST


More From » jquery

 Answers
440
$(document).ready(function(){

$(.button.postfix.login).on(click, function() {

var username = $(#username).val();
var password = $(#password).val();

if ((username != ) && (password != )) {
hide(); <-- hide pop ups about empty field
checkUser(username, password); // Pass the variables here as a parameter
} else {
$(#empty).show();} <-- pop ups
});

// Put the parameters here
function checkUser(username, password) {

$.ajax({
type: 'POST',
url: 'ajax/checkUser.php',
data: { username:username, password:password} //It would be best to put it like that, make it the same name so it wouldn't be confusing
success: function(data){
alert(data);
},
});
};


});



So when you're gonna call it on php



$username = $_POST['username'];

echo $username;

[#70868] Thursday, May 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;