• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

jquery my html value of a div disappears after showing

Hi,


my login procedure looks like this:

  $("#btnLogin").click(function() {
            var email = $("#email").val();
            var pw = $("#pw").val();
         
            $.get("../Admin/loginForum.aspx", { email: email, pw: pw, mem: "mem" },
                    function(data) {
                        $("#LogResponse").html(data.message);
                        $("#LogResponse").show();
                        if (data.success) {
                            $("#LogResponse").after('<span class="error">bla bla bla</span>');
                        }        
                    }, 'json');
        });


the html is:


 <table id="tblLoginForum" class="News" width="100%">
                    <tr>
                        <td colspan="2"><b>Login Forum</b></td>
                    </tr>
                    <tr>
                        <td>
                            user name (Email)</td>
                        <td>
                            <asp:TextBox ID="email" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            password</td>
                        <td>
                            <asp:TextBox ID="pw" runat="server" TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                        <td>
                            <asp:Button ID="btnLogin" runat="server" Text="login" Font-Bold="True" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" >
                           <div id="LogResponse"></div></td>
                    </tr>....


after the login is pressed and the $get returns with success,
the return data is placed in the right place and the messege below as well,
but if seems that the page is being refreashed after a few seconds and everything disappears

Can anybody tells me why? and what should I do to avoid it?

thanks
0
nuritat
Asked:
nuritat
  • 2
1 Solution
 
JonNormanCommented:
try adding event.preventDefault(); in the click event:
        $("#btnLogin").click(function(event) {
            event.preventDefault();
            var email = $("#email").val();
            var pw = $("#pw").val();
         
            $.get("../Admin/loginForum.aspx", { email: email, pw: pw, mem: "mem" },
                    function(data) {
                        $("#LogResponse").html(data.message);
                        $("#LogResponse").show();
                        if (data.success) {
                            $("#LogResponse").after('<span class="error">bla bla bla</span>');
                        }        
                    }, 'json');
        });

Open in new window

You also need to add event as a parameter in the click function as above
0
 
JonNormanCommented:
event.preventDefault would have done the same thing, without having to change the button, javascript would have stopped the server side code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now