通过javascript ajax将多个值发布到php

时间:2022-09-25 15:55:55

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.

我目前正在开发一个php项目。我需要将两个值(用户名和密码值)发布到php脚本以检查用户帐户是否存在。

I have it working fine posting the username only but don't know how to post multiple values to it.

我有它只是张贴用户名,但不知道如何发布多个值。

Below is the code that I currently have

下面是我目前的代码

function checkAccount()
        {
            var username = $(\'#txtUsername\').val();
            var password = $(\'#txtPassword\').val();

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

For the line

对于线

$.post("phpHandler/login.php"), {username: username},

$ .post(“phpHandler / login.php”),{username:username},

I tried to do

我试着这样做

$.post("phpHandler/login.php"), {username: username, password: password}, but this doesn't seem to work.

$ .post(“phpHandler / login.php”),{username:username,password:password},但这似乎不起作用。

Thanks for any help you can provide

感谢您的任何帮助,您可以提供

2 个解决方案

#1


3  

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:

您的.post调用中的转义引号和早期关闭数据之间存在语法错误。假设您的支持代码中不存在其他问题,此代码将起作用:

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");
            }
        }
    );
}

#2


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函数的括号。

#1


3  

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:

您的.post调用中的转义引号和早期关闭数据之间存在语法错误。假设您的支持代码中不存在其他问题,此代码将起作用:

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");
            }
        }
    );
}

#2


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函数的括号。