[英]Getting the result of a Jquery $form.submit() call
我有一个要使用 jquery.attr 值添加的表单,然后调用提交:
$form.attr("method", "POST");
$form.attr("action", "test.jsp");
$form.attr("target", "blank");
$form.submit();
我想知道是否有办法从我调用的 jsp 文件中获取响应?
就像是
$form.submit().response?
谢谢
如果您希望在不刷新页面的情况下获得响应,则需要执行 AJAX 请求。 这可以通过执行以下操作来执行:
$(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); }
);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.