I am sure this is a basic one.
I am not sure how to describe this but when I press return in an input field it changes the URL to put the input name and value pair in the URL, e.g. for this code :
<form name="searchForm"> <input name="searchTerm"> </form>
after having typed “fred” in the searchTerm field and pressed return, the URL changes to
test.html?searchTerm=fred
The thing is I have a submit button to do an XMLhhtprequest how do I stop this URL change?
Just handle the
submitevent for the form. The easiest (but ugliest) way to do it is this:But since you have Ajax set up (which should be listening to
submitanyways) useevt.preventDefault();orreturn false;there instead. Also remember to only cancel when the request appears to have succeeded!