dtuct88226 2016-01-01 03:53
浏览 49
已采纳

无法从骨干网检索PHP的JSON参数

I save my backbone model with no id therefore it uses the POST protocol to send parameters to my REST API. However I'm unable to catch these parameters, the PUT works just fine and updates the DB but POST method seem to cause problem. One thing I have noticed is that I can catch string parameters but integer parameters are returning as undefined.

my php

if($request_method == 'POST') {
$post_data = file_get_contents("php://input"); 
$post_data = json_decode($post_data, TRUE);
echo $post_data['name'];
}

backbone code

createdata: function(event){
    var newModel = new App.Models.Question({name:$("#_name").val(), surname:$("#_surname").val(), age:$("#_age").val()});
    newModel.save({},{
        success: function (model, response) {
            alert(response.responseText);
            },
            error: function (model, response) {
                alert(response.responseText);
            },      
            wait: true
        }

    );

    console.log(this.myCollection.toJSON());

},
  • 写回答

1条回答 默认 最新

  • duanqun9618 2016-02-17 06:33
    关注

    It has been a while I have completed this project but still I wanted to post the code that was working fine for me.

    createdata: function(event){
                var newModel = new App.Models.Quiz({ 
                    name:$("#name").val(), 
                    surname:$("#surname").val(), 
                    age:$("#age").val()});
    
                newModel.save({wait:true},{
                    success: function (model, response) {
                            $("#blanket").hide();
                            $("#create_popup").hide();
                        },
                        error: function (model, response) {
                            alert(response.responseText);
                        },      
                    });
                this.personCollection.add(newModel);
                console.log(this.quizCollection.toJSON());
            },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条