I’m getting this output after serializing a form using serialize().
cambio_estado_factura%5Bestado%5D=1
As the doc says, I expected something in this format:
a=1&b=2&c=3&d=4&e=5
This is the form I’m serializing:
<form id="cambio_estado" action="">
<div class="fld ">
<label for="cambio_estado_factura_estado">Estado</label>
<ul class="radio_list">
<li>
<input name="cambio_estado_factura[estado]" type="radio" value="1" id="cambio_estado_factura_estado_1">
<label for="cambio_estado_factura_estado_1">Recibida</label>
</li>
<li>
<input name="cambio_estado_factura[estado]" type="radio" value="2" id="cambio_estado_factura_estado_2">
<label for="cambio_estado_factura_estado_2">Registrada</label>
</li>
</div>
<input id="cambio_estado" type="submit" value="Cambiar">
</form>
And this is the jquery code:
$('form#cambio_estado').submit(function(e){
e.preventDefault();
alert();
console.log($('form#cambio_estado'));
var datos_formulario = $('form#cambio_estado').serialize();
console.log(datos_formulario);
$.post($("section#consultarFactura").data("url-cambio-estado"),
{"cambio_estado_factura": datos_formulario }
);
});
Any idea?
jQuery 1.6.1
This actually is the correct behavior for
serialize().Your issue is that the name in the form is
cambio_estado_factura[estado]. This would actually translate tocambio_estado_factura%5Bestado%5D, which is the escaped name of the element.Serialize()will take the name you use for each element on the form. If you want to have a different name appear on the resulting query string, use the appropriate names on the form itself.An example – this form will return
a=1&a=2on callingserialize()on it.EDIT:
Referring to your comments, this is my example of
parse_str:This returns:
Which means that you assume your array is single-level while in fact it is multi-level.