Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jquery my html value of a div disappears after showing

Posted on 2012-08-20
2
Medium Priority
?
595 Views
Last Modified: 2012-08-21
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
Comment
Question by:nuritat
  • 2
2 Comments
 
LVL 13

Expert Comment

by:JonNorman
ID: 38315294
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
 
LVL 13

Accepted Solution

by:
JonNorman earned 2000 total points
ID: 38315358
event.preventDefault would have done the same thing, without having to change the button, javascript would have stopped the server side code.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question