what is wrong with my jquery ajax form post? -


    $("button[name='advocate-create-button']").on("click", function () {     $.ajax({                     url: '/vendor/advocatecreate',         type: 'post',         datatype: 'json',         data: $('form#advocate-create-form').serialize(),         success: function() {             $(".modal_overlay").css("opacity", "0");             $(".modal_container").css("display", "none");         }         }).done(function (data) {         var $target = $("#advocate-list-view");         var $newhtml = $(data);         $target.replacewith(data);         $newhtml.effect("highlight");     });     return false; }); 

almost got this, need slight assist done...i'm trying post form data '/vendor/advocatecreate' , once saves, want dialogue go away , list behind updated.

the list behind advocatelist view , pulls data advocatelist method in same controller

advocatecreate method

[httppost]     [validateantiforgerytoken]     public actionresult advocatecreate(advocate advocate, int page = 1)     {         if (!modelstate.isvalid) return view(advocate);         db.advocates.add(advocate);         db.savechanges();          var userid = websecurity.getuserid(user.identity.name);          var model = (from in db.advocates.tolist()                      a.vendorid == userid                      select a).topagedlist(page, 15);         if (request.isajaxrequest()) return partialview("_advocatelistpartial", model);         return view(model);     } 

the form tag thus: <form class="form" id="advocate-create-form">

the create method called, data saved, lines under success: not fire , data in #advocate-list-view not updated

thanks

your service looks should returning html, , you're treating as-if should html, i'm going assume it's html. need either remove datatype option, or set html. since html not valid json, jquery triggering error handler rather success.

$("button[name='advocate-create-button']").on("click", function () {     $.ajax({                     url: '/vendor/advocatecreate',         type: 'post',         /*datatype: 'json',*/         data: $('#advocate-create-form').serialize(),         success: function() {             $(".modal_overlay").css("opacity", "0");             $(".modal_container").css("display", "none");         }         }).done(function (data) {         var $target = $("#advocate-list-view");         var $newhtml = $(data); // dunno          $target.replacewith(data); // goin on here         $newhtml.effect("highlight"); // or here     });     return false; }); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -