[英]How to use Ajax POST with jQuery in JSP?
This code works fine:这段代码工作正常:
$('#loginForm').attr('method', 'POST');
$('#loginForm').attr('action', basePath + url);
then I want to add a callback for handlling responsed messages and have a more common function for submission of a form, so I write a function as below:然后我想添加一个回调来处理响应消息,并有一个更常见的提交表单的功能,所以我写了一个函数如下:
//------ another function ----
saveCookie();
var loginFormParam = {
type: "POST",
url: basePath + "/sys/security/login.do"
};
prepareForm("loginForm", loginFormParam, loginCallback);
//----- end of another function
then,然后,
function prepareForm(whichForm, formAttr, callback) {
$("#" + whichForm).submit(function () {
$.ajax({
type: formAttr.type,
url: formAttr.url,
success: callback
})
})
}
But when the form submitted, I get a GET request not POST.但是当表单提交时,我收到一个 GET 请求而不是 POST。 I must misunderstand something but I don't know where.
我一定是误会了什么,但我不知道在哪里。
Thanks.谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.