Search code examples
postbackbone.jshttp-post

Backbone.js: POST request with empty value


I am trying to make a POST request. Here my code:

        var myModel = new MydModel({
            content: "ciao" 
        });
        console.log(myModel.get("content")); // "ciao"
        myModel.save();

If I look to the network activity it looks like this:

The response part {id:0, content:"", ……}

In the header part: Request Payload {"content":"ciao"}

Here my model:

define([], function () {
    var MyModel = Backbone.Model.extend({

        url: function url ()  
        {
            return "http://localhost/users";
        }
    });

    return MyModel;
});

Is it my problem or is it in the server part?


Solution

  • send/receive vs request/response

    • a server receives requests and sends responses
    • a client sends requests and receives responses

    in short

    • if {id:0, content:"", ……} (the response) is wrong, it's your server
    • if {"content":"asdasdsa"} (the request) is wrong, it's your client