Skip to content Skip to sidebar Skip to footer

Post Multiple Values Via Javascript Ajax To Php

I am currently working on a php project. I need to post two values, a username and password value to a php script to check that a user account exists. I have it working fine posti

Solution 1:

You have syntax errors all over the place between your escaped quotes and the early closing parens on your .post call. This code will work assuming no other issues exist in your supporting code:

function checkAccount()
{
    $.post(
        'phpHandler/login.php',
        {
            username: $( '#txtUsername' ).val(),
            password: $( '#txtPassword' ).val()
        },
        function( result )
        {
            if( result === 'unknownUser' )
            {
                $( '#msg' )
                    .html( 'Unknown username and password' )
                    .addClass( 'formError' )
                    .fadeIn("slow");
            }
        }
    );
}

Solution 2:

Try something like:

$.post("phpHandler/login.php", {username: username, password: password}, function(){
  // success code goes here
});

You are closing the parenthesis of post function before passing the parameters.


Post a Comment for "Post Multiple Values Via Javascript Ajax To Php"