What is this format for post method for form?

戏子无情 提交于 2019-12-13 05:27:00

问题


I saw this code on the internet, and I'm a little puzzled of what it does, particularly on the onsubmit portion.

  <form id="generateForm" method="post" action="#" onsubmit="return writeForm(event);">

Am I correct to assume that the onsubmit portion essentially runs writeForm method. The writeForm method then returns some value (ex. string) and then post sends it to where action is pointing to (#). If I'm not mistakent # means it isn't being sent anywhere.

On another point, how would I even grab that value in nodejs? Say it does what I think it does and sends for example a string representing an xml file, I don't think I can do something like in nodejs.

var recievedString = req.body.stringID

回答1:


Am I correct to assume that the onsubmit portion essentially runs writeForm method.

Yes.

The writeForm method then returns some value (ex. string)

Yes.

and then post sends it to where action is pointing to (#)

No.

If the value returned by the onsubmit function is a true value, then it will submit the form as normal. It it returns a false value, then it will prevent the form from submitting.

If I'm not mistakent # means it isn't being sent anywhere.

No. The relative URL # is a reference to the top of the page. Using it as a form action doesn't really make sense since a new page load will be triggered anyway. It will just submit to the URL of the current page.



来源:https://stackoverflow.com/questions/51103608/what-is-this-format-for-post-method-for-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!