Solved

re-load page

Posted on 2013-11-27
7
358 Views
Last Modified: 2013-11-27
I am using jquery to send data to a php file using get.

                                <script>
                                function login(myform) {
                                        $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                                $("#login-scr").html(php_msg);
                                        });
                                }
                                </script>

Open in new window


The code passed the data just fine. On my login.php file after I validate there login I do 2 things.

1. If the login is incorrect I display the login page again with a error message. This works with no problems.

2. Or if login is success I set sessions then use a meta refresh tag to re-direct the visitor to the URL they were before login. The meta refresh is not working.

print "<meta http-equiv=\"refresh\" content=\"2;url=$_SESSION[uri]\"> \n";

Open in new window


Error reported from FireBug:


SyntaxError: syntax error
      

<meta http-equiv="refresh" content="2;url=http://www.liveabo

jquery-1.9.1.js (line 611)
0
Comment
Question by:Robert Saylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 39681091
I don't think you can use a meta-refresh by ajax. The meta tag is only read on the initial page load. I think you should probably do the page reload entirely with javascript. For example:

function login(myform) {
                                        $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                                if (valid_login)
                                                     window.location.replace(url);
                                                else
                                                     $("#login-scr").html(php_msg);
                                        });
                                }
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39681099
I was kinda thinking meta refresh was not supported.

On my php script if the login is valid what would I call back to the parent so it knows it's valid to perform the refresh?
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 39681158
there are a couple of ways to do that. The easiest way is for your php script to return a url if the login is successful and a web page if it is not.

so in the above, you could have something like this:

                                                if (php_msg.substring(0,4) == "http")
                                                     window.location.replace(php_msg);
                                                else
                                                     $("#login-scr").html(php_msg);
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 7

Author Comment

by:Robert Saylor
ID: 39681733
PERFECT!!!!! Now all I need to do is show a quick success message then re-direct. I should be able to figure that one out. This one is going into my tool belt as I experienced this on another project as well.
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 39681738
THANK YOU and have a happy holiday!
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39681781
Here is the updated JQ with the delay: Works perfectly!

                                <script>
                                function login(myform) {
                                        $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                          if (php_msg.substring(0,4) == "http") {
                                             $("#login-scr").html('<span class="details-description"><br><font color=green>Login successfull. Loading please wait...</font><br></span>');
                                             $("#login-scr").delay(2000);
                                             window.location.replace(php_msg);
                                          } else {
                                             $("#login-scr").html(php_msg);
                                          }
                                        });
                                }
                                </script>

Open in new window

0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39681806
Sorry, the delay code did not work but the setTimeout did. Tested in firefox and Safari. On a mac here but IE "should" work the same.

                                <script>
                                function login(myform) {
                                        $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                          if (php_msg.substring(0,4) == "http") {
                                             $("#login-scr").html('<span class="details-description"><br><font color=green>Login successfull. Loading please wait...</font><br></span>');
                                             //$("#login-scr").delay(4000);
                                             setTimeout(function()
                                                {
                                                window.location.replace(php_msg)
                                                }
                                             ,2000);
                                          } else {
                                             $("#login-scr").html(php_msg);
                                          }
                                        });
                                }
                                </script>

Open in new window

0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 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