admin管理员组文章数量:1415120
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 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},
I tried to do
$.post("phpHandler/login.php"), {username: username, password: password}, but this doesn't seem to work.
Thanks for any help you can provide
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 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},
I tried to do
$.post("phpHandler/login.php"), {username: username, password: password}, but this doesn't seem to work.
Thanks for any help you can provide
Share Improve this question asked Oct 27, 2011 at 21:52 BoardyBoardy 36.3k108 gold badges271 silver badges463 bronze badges 2-
2
Why are you escaping the quotes in your $() calls? That turns the quotes into "part-of-the-string" so jquery is looking for some element literally named
'#txtPassword'
, and not an element with id#txtPassword
. – Marc B Commented Oct 27, 2011 at 21:57 - its because its within a php script and the html/javascript is surrounded with ' that's why its escaped so its not actually looking for '#txtPassword' – Boardy Commented Oct 27, 2011 at 22:05
2 Answers
Reset to default 3You 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");
}
}
);
}
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 multiple values via javascript ajax to phpStack Overflow
版权声明:本文标题:Post multiple values via javascript ajax to php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745225000a2648565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论