我可以在$ .post请求中使用jQuery的serialize()和其他变量吗? [英] can I use jQuery's serialize() and an additional variable in a $.post request?

查看:111
本文介绍了我可以在$ .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
);

这篇关于我可以在$ .post请求中使用jQuery的serialize()和其他变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆