2017-08-25 47 views
0

我在WordPress站点工作,我创建的自定义形式,在此我得到优惠券代码和验证此代码后,提交此表格到另一个URL,在表单动作定义,这里是这个jQuery工作,WordPress的表单不提交数据

<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提交,它首先重定向到301 POST方法,然后再生成不带参数的GET请求,并递交进行该网址,我已经倾倒在操作URL $ _REQUEST ,在这里没有得到任何数据,我也检查.htaccess和重定向插件,没有这样的URL存在重定向,问题是提交表单与post方法重定向,而与GET方法其工作正常,任何机构可以帮助

回答

0

您需要定义的操作功能,在您的function.php文件在你的主题,这将是这个样子

add_action('wp_ajax_nopriv_check_voucher_code', 'functiontohook'); 
add_action('wp_ajax_check_voucher_code', 'functiontohook'); 

之后,你需要指定你的动作,你已经做了Ajax请求。在函数中,您可以获取所有json数据并执行任何您想要执行的操作。如果有什么不清楚,请告诉我。我希望这会帮助你。

+0

我已经AREADY做到了这一点,我问错误在jQuery的侧 –

+0

也越来越从阿贾克斯正确有效的响应 –