XMLHttpRequest to Post HTML Form

后端 未结 6 2098
遇见更好的自我
遇见更好的自我 2020-12-01 04:50

Current Setup

I have an HTML form like so.

6条回答
  •  忘掉有多难
    2020-12-01 05:14

    I have had this problem too, I think.

    I have a input element with a button. The onclick method of the button uses XMLHTTPRequest to POST a request to the server, all coded in the JavaScript.

    When I wrapped the input and the button in a form the form's action property was used. The button was not type=submit which form my reading of HTML standard (https://html.spec.whatwg.org/#attributes-for-form-submission) it should be.

    But I solved it by overriding the form.onsubmit method like so:

    form.onsubmit = function(E){return false;}
    

    I was using FireFox developer edition and chromium 38.0.2125.111 Ubuntu 14.04 (290379) (64-bit).

提交回复
热议问题