Skip to content Skip to sidebar Skip to footer

Different Behavior Of Xmlhttprequest For Vs.

Consider the following code: index.html

Solution 1:

You would need <button type="button"> to reproduce the behaviour of <input type="button">.

If you omit the type on <button> it defaults to submit (except on IE<8 due to a bug; for this reason you should always use a type attribute on <button>). A submit button would cause the form to submit, causing a navigation and cancelling the XMLHttpRequest.

In general you should be trapping onsubmit on the form rather than onclick on a particular button, to ensure you always get informed if the form is submitted by another means such as Enter being pressed. (Consequently you'd use a normal submit button.) Use return false from the event handler to prevent the form submission from going ahead.

Post a Comment for "Different Behavior Of Xmlhttprequest For Vs.