I’m using YiiBackboneBoilerplate. I want to populate a model with data like this:
–model–
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone) {
var EvaluateModel = Backbone.Model.extend({
urlRoot: 'evaluate/process',
defaults: {
title: '',
state: 1
}
});
return EvaluateModel;
});
–in my view–
initialize:function() {
var result = new Evaluate({id:this.id});
result.fetch({
success: function(result, response) {
JSON.stringify(result.model);
}
});
},
– Yii action –
public function actionProcess() {
//I have tryed this
echo json_encode('test');
Yii::app()->end();
//and this
$this->sendResponse(200, CJSON::encode(array('title' => 'test')));
}
and i’m getting textStatus: parsererror and the result returned from the server contains html of the current page
Besides, the fetch() should send a POST request type according to initial setting in the app.js, but the type is GET
–app.js–
// initialize Http object to make backbone work with POST instead of GET
Http.initialize({type:‘POST’});
What could be wrong?