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());
            },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?