按下按钮并试图将数据发送到服务器时,Firebug:_145 is undefined?

这是我的源代码:

<script>
  function sendText(){
    require([ "dijit/form/Button", "dojo/_base/xhr"],
      function(Button,xhr) {

        xhr.post({
          url: "validURL1.html",
          form: dojo.byId("myForm"),
          load: function(data){
            var newStore = 
              new ItemFileWriteStore({url:'validURL2.html'});
            dijit.byId("grid").setStore(newStore);
          },
          error: function(error){
            alert("error!");
          }
        });
    });
  }
</script>

<button data-dojo-type='dijit.form.Button' onClick ='sendText()'>submit</button>

但是,当我按下按钮并试图将数据发送到服务器时,Firebug说:

_145 is undefined

我的密码怎么了?错误‘_145’是什么?

更新:

<script>

require([ "dijit/form/Button", "dojo/_base/xhr","dijit/form/Form",  "dojo/data/ItemFileWriteStore", 
          "dojo/dom-form","dijit/registry","dojo/ready", "dojox/grid/EnhancedGrid"],
        function(Button,xhr, Form, ItemFileWriteStore, domForm, registry,ready, EnhancedGrid) {
        var hasBeenSent = false;

        window.sendText = function() {

        xhr.post({
            url: "validURL1.html",
            form: dojo.byId("myForm"),
            handleaAs: "text",
            load: function(data) {
                var newStore = new ItemFileWriteStore({url:'validURL2.html'});
                dojo.byId("grid").setStore(newStore);
          },
          error: function(error){

            alert("error!");
          },
          handle: function() {

                hasBeenSent = true;
            }
        });

            }   
});
</script>

现在它显示:

TypeError: dojo.byId("grid").setStore is not a function

很显然,我需要实现“ enhancedGrid”,所以也许我应该请求其他模块或类?

You are using a compressed/minified version of dojo. The algorithm that does this will replace variable names with smaller ones (ie _145) to reduce the size of javascript file.

Looking through the compressed dojo file, I found this:

function formToObject(_145){var ret={},_146=dom.byId(_145).elements;

I would guess that dojo.byId("myForm") is not returning your form.

I would also recommend setting up your development environment to be able to use the uncomporessed files. It will allow for better debugging in the browser.

http://swingingcode.blogspot.com/2012/03/dojo-configurations.html

Change dojo.byId("grid") into dijit.byId("grid") as your call to dojo.byId("grid") will only return the DOMNode and not the Widget.

Also, make sure that if your 'grid' is a markup declaration, that the dojo.parser.parse() has run. if parseOnLoad:true is set, you'd need to wait for dojo.ready to fire, e.g. dojo.ready(function() { require.... }); or require(["dojo/domReady!", ....], function(..) { XHR });

Ultimately this construct will behave better, if only call inside your require statement is the update-xhr.

require([
     "dojo/parser", // Pull in parser to manually run it if parseOnLoad is not set true
     "dijit/form/Button",
     "dojo/_base/xhr",
     ...
     "dojox/grid/EnhancedGrid",
     "dojo/domReady!" // Wait untill DOM is done loading and all of the dojo base has been prepared
   ], function(
      Parser,
      Button,
      ...
   ) {
        Parser.parse();
        var hasBeenSent = false;

        window.sendText = function() {

        xhr.post({
            url: "sample/update.html",
            form: dojo.byId("updateUser"),
            handleaAs: "text",
            load: function(data) {
                var newStore = new ItemFileWriteStore({url:'sample/userLissts.html'});
                dijit.byId("grid").setStore(newStore);
          },
          error: function(error){

            alert("error!");
          },
          handle: function() {

                hasBeenSent = true;
            }
        });

            }   
});