dourenzhou8740
2019-04-11 10:27
浏览 83
已采纳

Ajax没有将变量传递给另一个页面?

I want to save user email to database when he clicks the subscribe button. But when I enter email and click the subscribe button it passes an empty array!

Subscribe form code:

<form id="cx-subscribe-user">
    <input type="text" name="email" id="email" placeholder="Enter Your Email" />
    <button type="submit" id="subscribe-button">Subscribe</button>
</form>

Js code:

$('#cx-subscribe-user').on('click', function (e) {
    e.preventDefault();
    var email = $('#email').val();
    $.ajax({
        type: "GET",
        url: "subscribe-the-user.php",
        processData: false,
        dataType: 'json',
        data: {email: email},
        success: function(data) {
            console.log('saved scucess');
        }
    });
});

In subscribe-the-user.php file I'm trying to var_dump the request but it's printing empty array:

var_dump($_GET);exit;

In var_dump I receive this empty array array(0) {}

图片转代码服务由CSDN问答提供 功能建议

我想在点击订阅按钮时将用户 email 保存到数据库。 但是,当我输入电子邮件并单击订阅按钮时,它会传递一个空数组!

订阅表单代码:

 <  code>&lt; form id =“cx-subscribe-user”&gt; 
&lt; input type =“text”name =“email”id =“email”placeholder =“Enter your Email”/&gt; 
&lt;  button type =“submit”id =“subscribe-button”&gt;订阅&lt; / button&gt; 
&lt; / form&gt; 
   
 
 

Js代码:< /strong>

nn
$('#cx-subscribe-user').on('click',function(e){
 e.preventDefault(); 
  var email = $('#email')。val(); 
 $ .ajax({
 type:“GET”,
 url:“subscribe-the-user.php”,
 processData:false,  
 dataType:'json',
 data:{email:email},
 success:function(data){
 console.log('saved scucess'); 
} 
}); 
}  ); 
   
 
 

subscribe-the-user.php 文件中我正在尝试var_dump请求但它正在打印空数组:< / p>

 <代码>的var_dump($ _ GET);出口; 
   
 
 

var_dump 中,我收到这个空数组 array(0){}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题