リクエストをチェックするための小さなアプリケーションを作成しています。私のアプリケーションはxmlからパラメータを読み取ると仮定しています
ここに私のコードがあります:
var JsonView = Backbone.View.extend({
template: _.template($('#json-view').html()),
invokeService: function () {
var _this = this;
//loading animation
$.mobile.loading('show', {
text: 'request sended',
textVisible: true,
theme: 'e',
textonly: false
});
_this.prepareParams();
console.log('params-'+ _this.params); // params-null
console.log('url-'+ _this.url); // url-/api/wines
$.ajax({
type: _this.model.get('action'), //GET or POST or PUT or DELETE verb
timeout: 2000,
cache: false,
url: _this.url,
data: _this.params,
contentType: 'application/json; charset=utf-8', // content type sent to server
dataType: 'json', //Expected data format from server
processdata: _this.processdata, //True or False
success: function (data) {//On Successfull service call
_this.displayJson(data);
},
error: function (data, status, error) {
_this.displayJson({ error: data });
},
complete: function (msg) {
$.mobile.loading('hide');
_this.$el.trigger('expand');
}
})
},
prepareParams: function () {
this.url = this.model.get('path');
this.processdata = (this.model.get('action') == 'GET');
//build data of the request from "params":
this.params = {};
var beforeparams=[],afterparams='';
_.each(this.model.get('params').models, function (param) {
if (param.get('placein')) {
switch(param.get('placein')){
case 'before':
beforeparams.push( param.get('defaultValue'));
break;
case 'after':
afterparams = afterparams + param.get('name')+'='+ param.get('defaultValue')+'&';
break;
}//end of switch
}
else
this.params[param.get('name')] = param.get('defaultValue').replace(/\'/g, '\\"');
}, this);//end of each
//take care of before params:
if(beforeparams.length>0)this.url =this.checkIfHasLast(this.url ,'/')+ beforeparams.join('/');
//take care of after params:
if(afterparams!=''){
afterparams=afterparams.substring(0,afterparams.length-1);//remove last '&'
this.url =this.checkIfHasLast(this.url ,'?') +afterparams;
}
//take care of usual params:
//avoid stringify for get
if((this.model.get('action') !== 'GET' )) this.params=JSON.stringify(this.params);
//no params
if(this.model.get('params').models.length==0){ this.params=null; }
return this.url ;
},
checkIfHasLast: function(url ,charMustBeLast){
return (url[url.length-1]==charMustBeLast) ? url : url+charMustBeLast;
},
displayJson: function (data) {
var jsonstring = JSON.stringify(data, undefined, 2);
var msg = this.syntaxHighlight(jsonstring);
this.$el.find('pre').html(msg);
},
render: function () {
this.$el.html(this.template());
this.$el.attr("data-role", "collapsible").attr("data-theme", "c").attr("data-content-theme", "d");
return this;
}
});
リクエストが送信され、期待されるjsonが取得されますが、開発者ツールで迷惑なメッセージが表示されます:
XHR finished loading: "http://localhost:8080/api/wines?_=1374143463089"
この「_=1374143463089」がどこから来たのか誰か説明してくれたらとてもありがたいです