0

私の DOH フレームワークは nodejs によって実行されます。(バージョンは1.10)

xmlhttprequestXHRリクエストを完了するには、nodejsがまたは他のモジュールを使用する必要があることを私は知っています。私の場合、nodejs XHR を直接使用するつもりはありませんが、代わりに dojo の xhr を使用します。どうやら、dojo の xhr は nodejs で実行できません。nodejs は npm モジュールなしでは 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
4

1 に答える 1