您如何将标题设置为";接受;放置或发布时dojo.store.JsonRest中的application/json?
在放置或发布时,如何将dojo.store.JsonRest中的头“Accept”值设置为application/json您如何将标题设置为";接受;放置或发布时dojo.store.JsonRest中的application/json?,dojo,Dojo,在放置或发布时,如何将dojo.store.JsonRest中的头“Accept”值设置为application/json var dataStore = new dojo.store.JsonRest({ target : "/project-services/" }); dataStore.put({id: 10, field1: "Some Value", field2: "Other Value"}); 当前发送的标头为: 接受text/html、application/xh
var dataStore = new dojo.store.JsonRest({
target : "/project-services/"
});
dataStore.put({id: 10, field1: "Some Value", field2: "Other Value"});
当前发送的标头为:
接受text/html、application/xhtml+xml、application/xml;q=0.9,/;q=0.8看起来头信息不是PUT和POST的选项,所以我决定简单地扩展dojo.store.JsonRest
/**
* Extend the dojo.store.JsonRest
*/
if(!dojo._hasResource["ext.store.JsonRest"]) {
dojo._hasResource["ext.store.JsonRest"] = true;
dojo.provide("ext.store.JsonRest");
dojo.require("dojo.store.JsonRest");
dojo.extend(dojo.store.JsonRest, {
put: function(object, options){
options = options || {};
var id = ("id" in options) ? options.id : this.getIdentity(object);
var hasId = typeof id != "undefined";
return dojo.xhr(hasId && !options.incremental ? "PUT" : "POST", {
url: hasId ? this.target + id : this.target,
postData: dojo.toJson(object),
handleAs: "json",
headers:{
"Content-Type": "application/json"
, "If-Match": options.overwrite === true ? "*" : null
, "If-None-Match": options.overwrite === false ? "*" : null
, "Accept": "application/javascript, application/json"
}
});
},
});
}
我今天也遇到了同样的问题,最后找到了像你一样的解决办法。PEM in#dojo建议我为它创建一个trac条目,因此希望它在不久的将来会得到修复