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
233 views
in Technique[技术] by (71.8m points)

javascript - 形式动作的替代(Alternative for Form Action)

I have this form in my web page(我的网页上有此表格)

<form method="POST" action="http://www.example.com/gotothisURL"> ........ Two buttons here , one for submit and one for validation </form> Now when I click "Submit" , the page is redirected to the URL, but it also does the same thing when I click "Validation".(现在,当我单击“提交”时,页面将重定向到URL,但是当我单击“验证”时,它也执行相同的操作。) I don't want page to be redirected on click of "validation", but I do want to do some cross site validation on server side.(我不希望在单击“验证”时重定向页面,但是我确实想在服务器端进行一些跨站点验证。)   ask by yogsma translate from so

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

1 Answer

0 votes
by (71.8m points)

The validation should work in two steps.(验证应分两个步骤进行。)

Firstly the form must validate on the client side, using JavaScript.(首先,表单必须使用JavaScript在客户端进行验证。) Then once the client side script has determined the form is valid it can be sent to the server for further validation.(然后,一旦客户端脚本确定表单有效,就可以将其发送到服务器以进行进一步的验证。) Unless there is a specific reason for the validation button I would avoid using this.(除非有特定的验证按钮原因,否则我将避免使用此按钮。) Just allow the form to be validated by JavaScript when the user clicks submits, if it passes the initial validation then it can be sent to the server, otherwise, you can display relevant messages on the screen explaining to the user what they must do in order for the form to be valid.(只需让表单在用户单击提交时通过JavaScript进行验证即可,如果它通过了初始验证,则可以将其发送到服务器,否则,您可以在屏幕上显示相关消息,向用户解释他们必须按顺序执行的操作表格才有效。)

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

...