javascript - jQuery: pushing values in .serializeArray(); -
i'm working on ajax form submition in jquery.
i used .serializearray()
function serializing form, need add together element obtained object, used push()
function.
so may that:
{ name: "test", surname: "test", action: "register" }
when serialize form, name , surname field sent, action field not. send informations php echo function but, console.log()
result, show name , surname, not action.
i tried .serialize()
function to, i'll still not obtain needed.
here fiddle.
$(document).ready(function () { $("#register").on("submit", function (e) { e.preventdefault(); var info = $("#register").serializearray(); data.push({name: "action", value: "register"}); console.log(data); jquery.post("/echo/json/", data, function () { alert("success"); }, "json"); }); });
the problem sending 2 requests, disable form submit:
$( '#register' ).on( 'submit', function() { homecoming false; });
or can place submit button outside form.
javascript jquery ajax
No comments:
Post a Comment