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) {}

  • 写回答

4条回答 默认 最新

  • drug95107 2019-04-11 10:32
    关注

    remove the processData, as documentation states, it will mess up your request

    processData (default: true)

    Type: Boolean

    By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false. https://api.jquery.com/jQuery.ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助