Is it very bad to set form method to ajax
when submitting the form with jquery ajax like so?
HTML:
<form method="ajax" action="scriptName">
<input type="submit" name="submit" value="submit">
</form>
JS:
$("form[method=ajax]").submit(function(e){ // <--
e.preventDefault();
/* ... */
});
It works, but there's a lot of things that works, but not necessary should be done just because it seems to be ok.
The ajax script is executing a script.exe.php
that will handle the request. This file detects both $_GET['script']
and $_POST['script']
requests, and then includes the corresponding script from a white-list.
The very same file, script.exe.php
, is also included at the begining of index.php
.
if($_REQUEST['script']){ include 'script.exe.php'; }
?script=
(not shown above) is optional in the form action attribute on ajax request. But not for non-ajax request. But by adding it to both could potentially prevent total failure if javascript is not activated.
Because if something fails, and for some reason the form is submited without ajax, I suppose the form would submit and cause a page redirect to whatever is in the action attribute. Which would be ?script=scriptName
.
And since this action will get detected by the $_REQUEST['script']
. The form would get submitted as expected?
I could of course supply a class for the javascript to detect instead of using the form attribute. Like normal folks do.
<form class="ajax" action="?script=scriptName">
$("form.ajax").submit(function(e){
Here I'm just asking. I would gladly know what danger this could have in practice. Or if it's not a big deal at all...