jquery - Change FORM element to something else or delete it while keeping all child elements -
i've integrated asp.net mvc sharepoint site. works great. i'm using default sharepoint master page (~masterurl/default.master
namely). problem particular master page has whole page wrapped in form
element while sharepoint pages normal asp.net webform pages.
my mvc content should have it's own form
, input elements i'd submit server. ajax calls not problematic. i'm not able use $("form").serializearray()
if keep original form
element. nonetheless normal postbacks problematic, since there's webform functionality on submit events , send way data server.
i using normal postbacks ajax postbacks. main problem being normal postbacks.
so have 2 possibilities both should run on $(document).ready()
:
- delete form element , keep other content is. in jquery mean prepend
form
elementdiv
, move content div , deleteform
. - directly change
form
elementdiv
. faster in terms of browser processing, don't know how it.
so if can elaborate solution 2. , provide input on these 2 possible solutions: 1 should done , why.
edit
there's third possibility well. create input elements neede containe them inside div
element. when user want submit form (div
not form anyway) could:
- dynamically call
$("div.form").serializearray()
- create form element
- populate serialized values
- append form body
- submit it.
seems tedious work. still first 2 solutions seem simpler.
if you're submitting via $.ajax()
i'd go .serialize()
of elements directly, this:
$.ajax({ url: "path/action", type: "post", data: $("#somecontainer :input").serialize(), success: function(data) { //do } });
or shorter $.post()
version:
$.post("path/action", $("#somecontainer :input").serialize(), function(data) { //do });
this doesn't require <form>
generation or other trickery, normal jquery ajax post (or get
, whatever's needed).
Comments
Post a Comment