weixin_33698043 2017-06-17 07:19 采纳率: 0%
浏览 29

Ajax发送isaute

I'm trying to send some data to save.php in order to save it in db. The thing is: Ajax post i success and it's returning right data in a console but 'echo' in save.php is returning nothing.I don't know what's wrong with this code.

var $nick = $('span.nick').html(); 
var $scores = points;
var range = n2;
var $upgrades =
    {
        'numbers': range,
        'pointsPerSec': pps,
        'multip': multi
    };


    //Save to DB
    $.ajax({
        url: "save.php",
        type: "POST",
        data: {
            userID: $nick,
            userPoints: $scores,
            userUpgrades: $upgrades
        },
        async: false,
        cache: false,
        success: function(){
            alert('Data saved');
            console.log(save);
            getData();
        },
        error: function(){
            alert('You fucked up mate :(');
        }
    });



function getData(){
    $.ajax({
        type: 'GET',
        url: 'save.php',
        async: false,
        cache: false,
        success: function(data){
            data = $.parseJSON(data);
            $.each(data, function(i, save){
                console.log(save);
            });
        },
        error: function(){
            alert('Error Ajax');
        }
    });
}

Here's my save.php file

if(isset($_POST['userPoints']) && !empty($_POST['userPoints'])){
     $post=$_POST["userPoints"] or $_REQUEST["userPoints"];
     $dec_post=json_decode($post);
     echo $dec_post;
}
  • 写回答

3条回答 默认 最新

  • weixin_33724059 2017-06-17 07:20
    关注

    you did not passed any parameter in your ajax success function, to retrive and console data in success function you should pass a parameter in the success change your ajax success function as

    success: function(response){
        alert('Data saved');
        console.log(response);
        getData();
    },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败