Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:23:36+00:00 2026-06-09T04:23:36+00:00

My question is as follows: I am creating a login for a jquery mobile

  • 0

My question is as follows:

I am creating a login for a jquery mobile application. I am doing this by a standard html login form. After i click the submit button, i am checking if the username and password provided are correct. I check this by using Ajax and json. Now the problem is as follows, if i do the following:

function authenticate(userName, password1) {

                    $.ajax
                    ({
                        type: "POST",
                        //the url where you want to sent the userName and password to
                        url: "http://notgiven",
                        dataType: 'json',
                        async: false,
                        //json object to sent to the authentication url
                        //data: {"username": "' + userName + '", "password" : "' + password + '"},
                     data: { username: "user1", password: "test1" },,
                        success: function (data) {
                            //do any process for successful authentication here
                            alert('Login status: ' + data.status);
                        }
                     })
                };

Then i get a success,

But if i want to get the parameters from my fields and do this:

$(document).ready(function() {
                                  //event handler for submit button
                                  $("#btnSubmit").click(function () {
                                                        //collect userName and password entered by users
                                                        var userName = $("#username").val();
                                                        var password = $("#password").val();


                                                        });

                });


                function authenticate(userName, password1) {

                    $.ajax
                    ({
                        type: "POST",
                        //the url where you want to sent the userName and password to
                        url: "http://notgiven",
                        dataType: 'json',
                        async: false,
                        //json object to sent to the authentication url
                        //data: '{"username": "' + userName + '", "password" : "' + password + '"}',
                      data: '{username: userName, password: password1 }',
                        success: function (data) {
                            //do any process for successful authentication here
                            alert('Login status: ' + data.status);
                        }
                     })
                };

Then i get a fail…
Any one know why???

ANSWER:*ANSWER:*ANSWER:*ANSWER:*

I have put : authenticate(userName,password);
into the click function as Thrustmaster said.
Done this because otherwise the data of username and password while clicking are going out of scope as Andrew said.

I’ve also put return false; at the .click function so that i can click the button more than once(and still getting results of function authenticate).

THNX

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:23:37+00:00Added an answer on June 9, 2026 at 4:23 am

    Aren’t username and password are out of scope after the click event. Or I got my closures wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Everyone This is a question about how to creating a widget in my application.
This question follows on from a previous question, that has raised a further issue.
This question follows on from a previous question. However stackoverflow presents me from commenting
this follows on from my last question which I thought was answered but for
This problem follows on from a previous question . When I run the following
I recently asked a question about creating elements with jquery. Specifically I needed input
Hey, I have decided to reword this question (as opposed to creating a new
This is partly a jquery question, but most javascript. I just don't know javascript
This follows this question which was solved using this answer . Long story short:
This question follows my previous question here in case anyone is interested. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.