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 7446661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:22:29+00:00 2026-05-29T12:22:29+00:00

I have a link on my site which opens a modal dialog with the

  • 0

I have a link on my site which opens a modal dialog with the login form. I use AJAX to send the login data to the server and but somehow, the .click() event doesn’t work. I guess its because I load the html with .html().

Here’s the code:

$('#loginLink').click(function(e) {
            e.preventDefault();
            $('<div id="loginContainer" title="Login"></div>')
            .html('<?php echo str_replace(array("\r\n", "\r", "\n"), "", $this->element("ajax/login")); ?>')
            .dialog({
                modal: true,
                resizable: false,
                position: 'top'
            });
        });
        $('#UserLoginForm input[type=submit]').click(function() {
            e.preventDefault();

            var form = $('#UserLoginForm').serialize();

            $.ajax({
                type: 'POST',
                url: '/login',
                dataType: 'json',
                data: form,
                beforeSend: function(XMLHttpRequest) {
                    $("#loginContainer .ajaxloader").show();
                },
                success: function(data) {
                    var message = $("#loginContainer > .flashMessage");

                    if(data.status == 'success') {
                        location.href = '/account';
                    } else {
                        message.text(data.msg);
                        message.show();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $('#loginContainer .ajaxloader').hide();
                    $('#loginContainer > .flashMessage').text('There was an error.').show();
                },
                complete: function(XMLHttpRequest) {
                    $("#loginContainer .ajaxloader").hide();
                }
            });
            return false;
        });

This part loads the content from a file:

<?php echo str_replace(array("\r\n", "\r", "\n"), "", $this->element("ajax/login")); ?>

And outputs:

<div class="flashMessage fail"></div><form action="/login" controller="users" id="UserLoginForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div><div class="input text required"><label for="UserEmail">E-Mail</label><input name="data[User][email]" style="width: 267px;" maxlength="64" type="text" id="UserEmail"/></div><div class="input password required"><label for="UserPassword">Password</label><input name="data[User][password]" style="width: 267px;" type="password" id="UserPassword"/></div><div class="submit"><input type="submit" value="Login"/></div></form><div class="ajaxloader"><img src="/img/icons/ajax-loader.gif" alt="" /></div><div class="clear" style="line-height: 8px;">&nbsp;</div>

Everything works fine except the .click() part to send the AJAX request :/ Im not that good in Javascript, so I don’t know what exactly the error is.

  • 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-05-29T12:22:33+00:00Added an answer on May 29, 2026 at 12:22 pm
    1. Any dynamic contents inserted into dom should use .on ( jQuery v1.7) or .live/.delegate ( before jQuery 1.7).
    2. You are missing quotes inside the attribute selector..
    3. As in other post, you missed to pass ‘e’ (event) argument.

    Using .on or .delegate is recommended over .live.

    Using .on [recommended]

          $('#loginContainer').on('click',  '#UserLoginForm input[type="submit"]', function (e) {
    

    Using .live,

          $('#UserLoginForm input[type="submit"]').live('click', function(e) {
    

    Using .delegate [recommended]

          $('#loginContainer').delegate('#UserLoginForm input[type="submit"]', 'click', function (e) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Site Map link that opens up a Web Resource .htm page.
We have uplaod function on our site. And uploaded file, displays link which on
I use PHP and MySQL to manage the content on my server/site (I have
I have a Django form which I load dynamically to a jQuery dialog after
I have created an asp.net site which works fine in internet explorer but for
I have a site (link below) where the clients work displays on a long
I have a link on my site that shows a random post, and the
I have textarea in my site(link shortening site) i want to user enter some
I have the list with like 100,000 site link strings Each link is unique,
I'm building a site using symfony php framework. I have a link in my

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.