0
我的D.O.H框架由nodejs運行。 (版本1.10)XMLHTTP在D.O.H中不可用
我知道應該的NodeJS使用xmlhttprequest
或其它模塊完成XHR請求。在我的情況下,我不是goona直接使用nodejs XHR,而是使用dojo的xhr代替。顯然,dojo的xhr無法運行nodejs。因爲沒有npm模塊,nodejs不能運行XHR。
是,任何可能性來解決這個問題?
命令:
node unittest.js load=doh test=test_custom_ajax.js
unittest.js:
global.dojoConfig = {
baseUrl: ".",
packages: [
{ name: "dojo", location: "./dojo" },
{ name: "dojox", location: "./dojox" },
{ name: "dijit", location: "./dijit" },
{ name: "my", location: "./my" }
]
}
require("./dojo/dojo.js");
custom_ajax.js:
define([
"dojo",
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/request/xhr"
], function(dojo, declare, lang, xhr) {
return declare("my.custom_ajax", null, {
ajaxGet: function(url, options) {
options = options || {};
return xhr(url, {
method: "GET",
handleAs: "json",
headers: {
"Content-Type":"application/json",
"Accept":"application/json"
},
}).then(
lang.hitch(this, function(data) {
/* handle data */
if (options.onHandle) {options.onHandle(resp)}
if (options.onLoad) {options.onLoad(resp)}
if (options.onComplete) {options.onComplete(resp)}
}),
lang.hitch(this, function(err) {
/* handle error */
if (options.onError) {options.onError(resp)}
})
);
}
});
});
個
test_custom_ajax.js:
define([
"doh/runner",
"my/custom_ajax"
], function(doh, custom_ajax) {
doh.register("test_custom_ajax", [{
var ca = new custom_ajax();
var options = {};
ca.ajaxGet('some_url', options);
}]);
}
結果:
Error: XMLHTTP not available