I want to submit a form using jquery .post()
. I want to send all the input names in addition to another parameter, in there any way to send data and the request?
$.post("RegistrarManagementServlet",{"option":"cancelRequest"},function(){
alert("hi");
});
here is how we submit the request
$.post("RegistrarManagementServlet",request,function(){
alert("hi");
});
I want to send all the data in the form (in the normal post request) in addition to option parameter, how can I make it?
EDIT
where should I define the request as function parameter, since the code occurs after confirmation dialog appear
开发者_C百科$('#cancelRequest').click(function(event){
event.preventDefault();
jConfirm('Are you sure to delete registrar request?', 'Confirmation Dialog', function(result) {
if(result == true){
request.cancelRequest="cancelRequest"; //request is not defiend
$.post("RegistrarManagementServlet",request,function(){
alert("hi");
});
}
});
request.option = "cancelRequest";
$.post("RegistrarManagementServlet", request, function(){
alert("hi");
});
You can make name value pair by using following code
var elem = document.getElementById('frmName').elements;
for(var i = 0; i < elem.length; i++)
{
//Make the pairs like
//{"option":"cancelRequest"}
//elem[i].name will give you the name and
//elem[i].value will give you the value of the field
}
then post your request just the way you do.
Or you can see the example at http://www.codeunit.co.za/2009/11/04/jquery-iterate-through-a-forms-elements/ for a Jquery way to do the same
You can use jQuery's $.extend()
: $.post('url', $.extend(request, {more: 'parameters'}), function...
精彩评论