i have slowly been moving from microssoft ajax to jquery for all my ajax stuff. the only thing i have left is some forms that are posting over using microsoft ajax by using Ajax.Beingform. This is an asp.net mvc site so submit should call a controller post action.
What is the simplest way to convert this to jquery so i can remove my reference to microsoft ajax.
It's probably easiest to use the jQuery Form plugin to achieve most of this functionality if you had a form that looks like:-
<%= Ajax.Form(new AjaxOptions {
Url = theUrl,
Method = theMethod,
Confirm = confirmFunction,
InsertionMode = InsertionMode.Before,
OnBegin = onBegin,
OnComplete = onComplete,
OnFailure = onFailure,
OnSuccess = onSuccess,
UpdateTargetId = elementId,
LoadingElementId = loadingElementId
});
This would correspond to a form plug-in call of:-
$("#yourFormId").ajaxForm({
url : theUrl,
type : theMethod,
beforeSubmit : confirmFunction,
beforeSend : onBegin,
complete : onComplete,
success : onSuccess,
error : onFailure
});
The only issues are replicating the LoadingElementId, UpdateTargetId and InsertionMode properties.
If you want to replicate InsertionMode.Replace you can pass the additional target option to the ajaxForm plug-in. If you want to replicate the remaining functionality you'd have to write your own beforeSend, success and complete event handlers.
Something like the following would simulate a form with InsertionMode.Before, UpdateTargetId = "Test", LoadingElementId = "Loader":-
$("#yourFormId").ajaxForm({
beforeSend : function() { $("#Loader").show(); },
complete : function() { $("#Loader").hide(); },
success: function(result) { $(result).prependTo("#Test"); }
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With