php - jQuery serialize() not working -
i have html form looks this:
<form class="form-horizontal" id="create_user" method="post" action="#" accept-charset="utf-8"> <span>username</span><input required="true" type="text" name="username" id="username"> <span>e-mail</span><input type="email" name="email" id="email"> <span>privileges</span><select id="role" name="role"><option value="1">administrator</option><option value="2">employee</option><option value="3">dealer</option></select> <span>password</span><input type="password" name="password" id="password"> <span>repeat password</span><input type="password" name="repeat_password" id="repat_password"> <input class="btn-primary btn" type="submit" value="submit"> <input class="btn-inverse btn" type="reset" value="reset"> </form>
i'm trying send info server using ajax, such:
$("form").submit(function(){ var form_data = $(this).serialize(); var request = $.ajax({ url: "user/validate", type: "post", data: form_data }); request.done(function (response, textstatus, jqxhr){ alert(response);//comes blank }) // callback handler called on failure request.fail(function (jqxhr, textstatus, errorthrown){ // log error console console.error( "the next error occured: "+ textstatus, errorthrown ); }); });
edit: here laravel controller handles post data:
class user_controller extends base_controller { public function post_validate() { homecoming input::get('username'); } }
however, no info sent using $(this).serialize()
. if individually pass each element doing this: $("#username").val()
, works fine. made sure form inputs had names, still didn't work.
i think page refreshed:
$("form").submit(function(e){ e.preventdefault(); //<-----try adding
php jquery ajax serialization laravel
No comments:
Post a Comment