Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

javascript - noob: how to show login error message on the same page after php server processes request

I have a login page. User first enters information and submits the form.

And I have a php script that will see if the user exists.

If( authenticated == true)  
{  
    // I do a redirect  
}  
else  
{  
  // I want to popup an error message on the same page.  
} 

1) I'm not sure how to show the popup message, I would like to make my div element visible with an error message returned from the server,
I would have to use Ajax, right? But how?

Or are there alternatives which are just as good.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

if you would use ajax, use it for the whole process. So, no such problems at all. Get response and show it to user.

But as you stated yourself as a newbie, I'd strongly advise you to do it straight and simple way, just to learn how the things are.

As a general rule, a redirect always preferred after POST method request. In some cases one can omit this, but for the login form you would use a session anyway. So, you can start a session, write an error information there and then do Location: redirect.

After it, check session for the errors, and then notify user using any method you wish: a div, or a popup or anything.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...