i have this jQuery-AJAX code below and a form:
<script type="text/javascript">
$(document).ready(function () {
$('form').submit(function () {
form_data = $(this).serializeArray();
$.ajax({
url: "/frontend_dev.php/coche1/update/id/1",
type: "POST",
data: form_data
});
});
return false;
});
</script>
As you can see I’m using serializeArray() but when i use serialize() it also works the same..
Why in both cases works the same? What of them should i use?
Im using symfony as php framework. I can offer you more info if you need it.
If an object/array gets passed (which
.serializeArray()returns), it’s serialized via$.param().If a string get passed (which
.serialize()returns) it doesn’t do anything further.…so they have the same effect when passed as the
dataproperty. You can find the relevant check here:Which one should you use? It really doesn’t matter here,
.serialize()makes the same$.param()call, so they do the exact same amount of work. I personally use.serialize()because it’s simply less to type.