Why usually <form> used to aggregate elements and not <div> in case when form working with ajax submit event?
Ajax jquery function:
$('#parse-form').submit(function() {
$.ajax({
url: 'controller.php',
type: 'POST',
dataType:'json',
success: function(data) {
alert(data);
}
});
return false;
});
Way1 – form:
<form>
<input type="text"/>
<button type="submit">submit</button>
</form>
Way2 – div:
<div>
<input type="text"/>
<button type="submit">submit</button>
</div>
(Maybe because when user press enter the form submitted, but in case of more than 1 form in webpage?)
Update:
If the reason to write form because javascript disable state true:
1.What should be added in code that form will have 2 option ajax submit and regular submit ?
2.Does this reason taking place when we have website that working with jquery ui or other javascript library ui (menu, catalog, etc..)
Thanks
More than one form is a possible reason, but the bigger issue is graceful degradation for users who have javascript turned off – just using divs locks out any user who has JS disabled.