Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Backbone is based on a REST API: when saving/updating a model to the server, Backbone will send it serialized as JSON in the request body with a <code>POST</code> our <code>PUT</code> request. From <a href="http://backbonejs.org/#Sync">Backbone.sync documentation</a></p> <blockquote> <p>With the default implementation, when Backbone.sync sends up a request to save a model, its attributes will be passed, serialized as JSON, and sent in the HTTP body with content-type application/json.</p> </blockquote> <p>This means that server-side you have to</p> <ul> <li>determine the type of request</li> <li>decode the serialized JSON</li> </ul> <p>Something like this should get you started</p> <pre><code>$request_method = strtolower($_SERVER['REQUEST_METHOD']); $data = null; switch ($request_method) { case 'post': case 'put': $data = json_decode(file_get_contents('php://input')); break; } // print_r($data); // note that mysql_* functions are deprecated // http://php.net/manual/en/function.mysql-query.php // inserting with a PDO object, assuming an auto incremented id $sql = "INSERT INTO boxes (x, y, w, h) VALUES(?, ?, ?, ?)"; $sth = $dbh-&gt;prepare($sql); $sth-&gt;execute(array( $data-&gt;x, $data-&gt;y, $data-&gt;w, $data-&gt;h )); $id = $dbh-&gt;lastInsertId(); </code></pre> <p>Check this page for a more thorough implementation of a REST API in PHP <a href="http://www.gen-x-design.com/archives/create-a-rest-api-with-php/">http://www.gen-x-design.com/archives/create-a-rest-api-with-php/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload