gpt4 book ai didi

javascript - dojo xhr发布问题

转载 作者:行者123 更新时间:2023-11-29 22:23:32 24 4
gpt4 key购买 nike

这是我的源代码:

<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”。所以也许我应该需要一些其他模块或类?

最佳答案

将 dojo.byId("grid") 更改为 dijit.byId("grid"),因为您对 dojo.byId("grid") 的调用将只返回 DOMNode 而不是 Widget。

此外,如果您的“网格”是标记声明,请确保 dojo.parser.parse() 已运行。如果设置了 parseOnLoad:true,您需要等待 dojo.ready 触发,例如dojo.ready(function() { require.... });require(["dojo/domReady!, ....], function(..) { XHR });

最终,如果仅在您的 require 语句中调用 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;
}
});

}
});

关于javascript - dojo xhr发布问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10912165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com