jquery - Unable to post a form using AJAX -


i trying post values using ajax not able so, watever may throwing fail.

$("#displayinfo").hide();    var csrftoken = document.getelementbyid("csrf").value;    var csrfname = document.getelementbyid("csrf").getattribute("name");     var postfrmdata = $('#'+formid).serialize();    var returndata= $.ajax({        url: "reportssearchresults",        type: "post",        data: postfrmdata,        datatype: "json",        beforesend: function(xhr) {           xhr.setrequestheader(csrfname, csrftoken);       }     });     returndata.done(function(res) {     alert("pass"+res); }); returndata.fail(function(data) { alert("fail"+data); }); return false;  

kindly tell reason why not getting submitted

you're doing wrong. think looking (not tested):

//if form submitted $('form').submit(function( e ) {     e.prevendefault();     $form = $(this); //get form      //post ajax request     $.ajax({         url: $form.attr('action'), //get action attribute of form         type: "post",         data: $form.serialize(), //serialize form         datatype: "json",         .done(function() { //or success: function() {                 alert( "success" );         })         .fail(function() { //or error: function() {                 alert( "error" );         })         .always(function() { //or beforesend: function() {                 alert( "complete" );         });     }); }); 

and tip: use firebug (firefox plugin/extension) test what's going on in background. work's great.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -