我可以在$ .post请求中使用jQuery的serialize()和其他变量吗?

问题描述:

当前,我有这行:

$.post("submitmail.php", $("#contactform").serialize(), recvMailStatus);

我是jQuery的新手,所以这可能是一个愚蠢的愚蠢问题.
但是我正在使用或不使用Javascript来使该项目正常工作,因此,如果使用此功能提交表单,我希望Submitmail.php只是回显它是否成功.如果表单只是提交并重定向到submitmail.php,我希望它显示的不是白色屏幕,而是黑色文本,上面写着邮件已成功发送".为此,我想到了post一个额外的变量"fromjs"或其他内容,以便页面可以相应地呈现自身.最好的方法是什么?

I'm new to jQuery so this may be an absurdly stupid question.
But I'm making this project work with or without javascript, so if a form is submitted with this function, I want submitmail.php to just echo whether or not it was successful. If the form just submits and redirects to submitmail.php, I want it to display something other than a white screen with black text saying "mail sent successfully." To do this I figured I would just post an extra variable "fromjs" or something so that the page can render itself accordingly. What's the best way to do that?

您可以将其附加到要发布到的地址:

You may append it to the address you are posting to:

$.post(
    "submitmail.php?formjs=some_value", 
    $("#contactform").serialize(), 
    recvMailStatus
);

或:

$.post(
    "submitmail.php", 
    $("#contactform").serialize() + '&formjs=some_value', 
    recvMailStatus
);