【发布时间】:2018-02-03 16:43:30
【问题描述】:
我在 wordpress 网站上工作,我创建了自定义表单,我在其中获取凭证代码,并在验证此代码后,将此表单提交到另一个 url,在表单操作中定义,这是用于这项工作的 jquery,
<script type="text/javascript">
$( document ).ready(function() {
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
$( "#submit_btn_redeem" ).click(function(event) {
event.preventDefault();
var form = $("#form-voucher");
var voucher_code = $("#voucher_code").val();
var btn = $(this);
if(voucher_code!=""){
$("#voucher_code").removeClass("error-fld");
btn.prop('disabled', true);
btn.attr("disabled","disabled");
$(".loading").show();
var action_data = {
'action': 'check_voucher_code',
'voucher_code': voucher_code
};
$.ajax({
type: 'POST',
url: ajaxurl,
data: action_data,
dataType: 'json',
success: function (response) {
$(".loading").hide();
btn.prop('disabled',false);
btn.removeAttr("disabled");
if(response.status==1){
$(".response").html(response.message);
$(".response").show().delay(2000).hide(0);
alert($("#voucher_code").val());
//return false;
setTimeout(function(){
document.getElementById("form-voucher").submit();
}, 1000);
}else{
$("#voucher_code").addClass("error-fld");
$(".response").html(response.message);
$(".response").show().delay(3000).hide(0);
}
}
});
}else{
$("#voucher_code").addClass("error-fld");
}
});
});
</script>
问题是当它在给定的 url 上提交时,它首先使用 POST 方法重定向到 301,然后再次生成不带参数的 GET 请求并提交到该 url,我在操作 url 上转储了 $_REQUEST,这里没有得到任何数据,我还检查了 .htaccess 和重定向插件,没有这样的 url 用于重定向,问题是使用 post 方法重定向提交表单,而使用 GET 方法可以正常工作,任何机构都可以提供帮助
【问题讨论】:
标签: php jquery wordpress forms .htaccess