I have a form that I'm adding to with jquery.attr values and then call submit:
$form.attr("method", "POST");
$form.attr("action", "test.jsp");
$form.attr("target", "blank");
$form.submit();
I was wondering if there is a way for me to get the response back from the jsp file that I call?
something like
$form.submit().response?
Thanks
If you are looking to obtain a response without refreshing the page, you need to perform an AJAX request. This can be performed by doing:
$(function(){
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
// If you want to serialze the form, you can use $(this).serialize() or $("form").serialize();
$.post(
'/test.jsp',
$(this).serialize(),
function(response) { console.log('response was:',response); }
);
// OR if you want to specify each form element
$.post(
'/test.jsp',
{
name: $('#name').val(),
email: $('#email').val(),
},
function(response) { console.log('response was:',response); }
);
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.