Solved

re-load page

Posted on 2013-11-27
7
355 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
  • 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 6

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

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 6

Author Closing Comment

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

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 6

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
css, html 5 18
CSS Position not returning 2 48
Set email body to html using vbscript 6 28
ASP.net Fit 3 divs on screen side by side 3 7
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now