Results 1 to 8 of 8

Thread: IE losing Jquery Functional

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default IE losing Jquery Functional

    I'm using this code

    Code:
    location.reload();
    in the result of a jquery ajax post and it works in ff, chrome, and safari. In IE it is losing the page the reload came from though and is calling it from the root directory. Does anyone know how to correct this? I don't have the site live so I can't provide a link.

    This is a the full function I have it executing at.

    Code:
    <script type="text/javascript">
    $('#pass').keydown(function(e) {
    	if (e.keyCode == '13') {
    		$('#status').html();
    		$.post("login.php", {user : $("#user").val(), pass : $("#pass").val()},
    		function(data){
    			if (data == "\r\nReload" || data == "Reload") {
    				location.reload();
    			}
    			if (data == "\r\nLogin Failed" || data == "Login Failed") {
    				$('#status').html('<span style="color:#f00; font-weight:bold;">Sorry, login failed. Please try again.</span>');
    			}
    		});
    	}
    });
    </script>
    Does anyone also know why the 'data' coming in from the '$.post' request has a new line in it some of the time?

    Thanks.

    EDIT:

    Forget an example

    site.com/dir/dir/page.php (so this triggers the reload)

    site.com/dir/dir/ (this is what ie loads)

    I need the reload so the session data is available to the php. I 'm using ajax so if the wrong user/password is entered there will be no session data, and error will be displayed.
    Last edited by bluewalrus; 01-13-2011 at 01:07 PM. Reason: bw- more detail? later js - remove bogus hotlinks
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Unless there's some reason not to, I'd try:

    Code:
    location = 'page.php';
    instead of:

    Code:
    location.reload();
    If the name of the page might vary, use PHP to supply it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (01-12-2011)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Thanks, that worked for the login click and enter key. For the logout it is not working though it still redirects to the directory.

    Code:
    $('#logout').live('click', function() {
    	$.post("login.php", {logout : true},
    	function(data){
    	if (data == "\r\nReload" || data == "Reload") {
    		location = 'header.php';
    	}
    	});
    });
    Is the "location" defined(usage?) in jquery or JS?
    Corrections to my coding/thoughts welcome.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It (location) is a javascript object. It's both a setter and a getter and it means the location of the page.

    Technically it's not a string though, so you might have better luck setting:

    Code:
    location.href = 'header.php';
    But I've never seen that be a problem before when used that way as just location. More likely this condition is false:

    Code:
    if (data == "\r\nReload" || data == "Reload")
    because, if it were true and the location directive fired, you would either get the page it's asking for or an error page if the page was not found. You wouldn't get a directory listing or an index page, which is what you seem to be saying that you're getting. What exactly are you getting?

    One other possibility is that there may be some kind of redirect (javascript, PHP, meta tag, etc.) on header.php which is causing it to load whatever it is that you're getting in place of header.php.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bluewalrus (01-13-2011)

  7. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I tried window.location.reload and location.href="page.php". I also tried location.href="http://www.google.com"; that didn't work in any browser. Here's a full example:

    PHP Code:
    <?php
    session_start
    ();
    ?>
    <link href="css.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript">
    $('#login').live('click', function() {
        $.post("login.php", {user : $("#user").val(), pass : $("#pass").val()}, 
        function(data){
        $('#status').html();
        if (data == "\r\nReload" || data == "Reload") {
            location = 'header.php';
        }
        if (data == "\r\nLogin Failed") {
            $('#status').html('<span style="color:#f00; font-weight:bold;">Sorry, login failed. Please try again.</span>');
        }
        });
    });
    $('#logout').live('click', function() {
        $.post("login.php", {logout : true},
        function(data){
        if (data == "\r\nReload" || data == "Reload") {
            location.reload();
        }
        });
    });
    </script>
    <body>
    <div class='header'>
                   <?php if(!isset($_SESSION['userid'])) {?>
                    <div id="status"></div>
                    <div class="login">
                        <form method="post">
                             <table cellpadding="0" cellspacing="0">
                                  <tr>
                                       <td width="200px;">&nbsp;</td>
                                       <td width="107"><a class="top_link" href="http://www.jove.com/index/Forgot Password.stp">Forgot Password</a></td>
                                       <td width="83"><a class="top_link" href="http://www.jove.com/index/CreateAccountF.stp">New Account</a></td>
                                       <td width="100"><input type="text" class="input_top login_name" name="login" value="Email" id="user" /></td>
                                       <td width="100"><input type="password" class="input_top login_pass" name="pass" id="pass" value="Password"/></td>
                                       <td width="69"><input type="button" class="submit" value="Sign In" id="login" /></td>
                                  </tr>
                             </table>
                        </form>
                   </div>
                   <?php }  else {?>
                   <div class="logout"  id="logout"><a href="">Log Out</a></div>
                   <?php ?>
                   <div class="clr"></div>
              </div>
    <script type="text/javascript">
    $('#pass').keydown(function(e) {
        if (e.keyCode == '13') {
            $('#status').html();
            $.post("login.php", {user : $("#user").val(), pass : $("#pass").val()},
            function(data){
                if (data == "\r\nReload" || data == "Reload") {
                    location = 'header.php';
                }
                if (data == "\r\nLogin Failed" || data == "Login Failed") {
                    $('#status').html('<span style="color:#f00; font-weight:bold;">Sorry, login failed. Please try again.</span>');
                }
            });
        }
    });
    </script>
    The reload comes through I tested that with breakpoints. found that I needed the \n\r also because that comes through some of the time.
    Corrections to my coding/thoughts welcome.

  8. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    hah think i found the problem
    Corrections to my coding/thoughts welcome.

  9. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    And that was?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I was calling it with an a and had an empty href="". I replaced it with a ? and it works now.
    Last edited by bluewalrus; 01-13-2011 at 02:10 AM.
    Corrections to my coding/thoughts welcome.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •