1、前端代碼創建模型,和《Backbone學習日記[2]:後臺(php)接收前端數據並保存》一文中的差很少:javascript
<script type="text/javascript" src="jquery.min.full.js"></script> <script type="text/javascript" src="Underscore.js"></script> <script type="text/javascript" src="Backbone.js"></script> <script type="text/javascript"> var M = Backbone.Model.extend({ defaults:{ name:'hello2' }, url:"save.php" }); var m2 = new M; m2.fetch({ url:"3.php", success:function(model,response){ alert(JSON.stringify(response)); } }); </script>
2、不一樣點是模型實例調用了fetch方法獲取後臺數據,而且在fetch方法中從新指定了後臺文件。利用fetch方法成功獲取後臺數據時的返回函數,對後臺數據進一步處理。php
3、後臺php代碼:前端
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; echo $json; ?>