我有一个使用AJAX请求提交五次的表单。我在这些表单标记之外有一个值 referer_fname ,我想将其附加到每个AJAX请求中。我怎样才能做到这一点?
到目前为止,我的脚本如下:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<!--serial submit ajax-->
<script>
function mySubmit(){
var myForms = document.getElementsByTagName("form");
for (var t = 0; t<myForms.length; t++){
$.post("http://", $(myForms).eq(t).serialize(), function (data, status) {
if (status === "success"){
window.location.href= "http://redirect.com";
}
}
)
}
}
</script>
答案 0 :(得分:1)
您可以附加到序列化表单字段输出(请参阅this the accepted answer on this post for reference)
function mySubmit(){
var myForms = $("form");
myForms.each(function(index) {
var form = myForms.eq(index);
var serializedForm = form.serialize();
serializedForm += '&referer_fname='+$('#refererFrame').val();
$.post("https://", serializedForm, function (data, status) {
if (status === "success"){
window.location.href= "http://redirect.com";
}
});
});
}