如何发布和使用backbonejs到php?
下面是我的代码,一个是ajax方式它工作正常将发布和抓取输出消息。但我现在正在学习backbonejs,是否正确使用fetch()获取和save()发布?如何以ajax方式输出相同的结果?
感谢。
PHP
<div class="con">
<?php
if($_POST){
// print_r($_POST);
print $_POST['name'];
}else{
print 'error';
}
?>
</div>
AJAX
JS
$.ajax({
type: "POST",
url: "inserts.php",
data: { name: "tim"}
}).done(function( msg ) {
var con = $(msg).filter('.con').html();
console.log(con);
});
output =&gt; print $ _POST ['name'] =&gt; tim
骨干 JS
Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;
var Person = Backbone.Model.extend({
// defaults: {
// name: 'undefined',
// age: 'undefined'
// },
urlRoot: "inserts.php",
});
person = new Person({name:"tim"});
person.save();
更新
person.save({
success: function(model,response, options){
console.log('success'); => nothing output
=> and how to output 'tim' in console.log
},
error: function(model, xhr, options){
}
});
答案 0 :(得分:0)
尝试
person.save({
success: function(model, response, options) {
},
error: function(model, xhr, options) {
}
});