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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀