Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...