骨干是基于REST API:当保存/更新模型到服务器,骨干会发送与请求体序列化为JSON
POST我们的
PUT请求。从Backbone.sync文档
使用默认实现时,当Backbone.sync发送保存模型的请求时,其属性将被传递,序列化为JSON,并在HTTP正文中使用内容类型application
/ json发送。
这意味着您必须在服务器端
- 确定请求的类型
- 解码序列化的JSON
这样的事情应该让你开始
$request_method = strtolower($_SERVER['REQUEST_METHOD']);$data = null;switch ($request_method) { case 'post': case 'put': $data = json_depre(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->prepare($sql);$sth->execute(array( $data->x, $data->y, $data->w, $data->h));$id = $dbh->lastInsertId();检查此页面,以在PHP http://www.gen-x-design.com/archives/create-a-rest-api-with-
php/中更全面地实现REST API 。



