道场/请求不确定的,尽管需要 [英] Dojo/request undefined despite require

查看:209
本文介绍了道场/请求不确定的,尽管需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与果园查看我尝试发布一个AJAX到服务器 dojo.request.post 功能相关的脚本。不过,我只得到 ESRI /请求道场/请求是不确定的。我打电话其中要求语句居住功能之外的要求,但有没有问题,其他所需的软件包,只要我使用他们在正确的格式。 道场/请求作品在我们的其他项目,所以我怀疑搞乱的东西了乌节(其他项目的道场/请求用途是在一个普通的网页,而不是在一个视图),但我希望由它引起的前面浮现的问题。

In a script associated with an Orchard view I try to post an AJAX to server with dojo.request.post function. However, I only get esri/request, dojo/request is undefined. I call the request outside the function where the require statements reside, but there's no problem with other required packages as long as I use them in correct format. Dojo/request works in our other project, so I suspect Orchard of messing things up (the other project's dojo/request use is in a plain page, not in a view), though I would expect problems caused by it to surface earlier.

的code重要部件:

require([ ... "dojo/request", ... ], function (... Request, ...) {
  //custom init function contents
})

function sendResults(featureSet) {
  //custom code processing the parameter, making uri, JSON and like
  dojo.request.post(uri, {
    //sending data
  })
}

我的剃须刀需要在同一个文件的部分包括:

My razor require part in the same file contains:

Script.Require("esri/JavaScriptApi").AtHead();
Script.Require("dojo").AtHead();

这些定义在 resourcemanifest.cs

 manifest.DefineScript("esri/JavaScriptApi").SetUrl("http://js.arcgis.com/3.14/");
 manifest.DefineScript("dojo").SetUrl("//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js");

我得到的错误,当我尝试运行code:

The error I get when I try to run the code:

TypeError: dojo.request is undefined

我在萤火对其进行了测试,并确认道场/请求不存在(相同的变种,如道场/请求),只有 ESRI /请求是一个函数,但它没有方法。

I've tested it in FireBug and confirmed that dojo/request doesn't exist (the same for variants, like dojo/Request), only esri/request is a function, but it has no post method.

我在这里停留。谷歌搜索导致没有有效输出平原纯粹的绝望(第5+)和我的同事不知道。有谁知道为什么我看不到道场/请求,以及如何得到的呢?

I'm stuck here. Google search lead to "plains of sheer desperation" (page 5+) with no useful output and my co-workers don't know. Does anyone know why I can't see dojo/request and how to get it?

推荐答案

据我所知,道场/请求不导出一个全球性的(如现代AMD模块通常不应该需要),所以 dojo.request 绝不会工作在任何情况下。

As far as I'm aware, dojo/request does not export a global (as modern AMD modules generally shouldn't need to), so dojo.request would never work in any context.

采用AMD模块适当的方法是使用它们的的一个要求回调的主体(或,甚至更好,组织你自己code。在AMD模块,以及,在定义工厂函数)。

The appropriate way to use AMD modules is to use them within the body of a require callback (or, even better, organize your own code in AMD modules as well, and use them within a define factory function).

require([ ... "dojo/request", ... ], function (... request, ...) {
  request.post(...);
})

另外,如果你一定道场/请求已加载你想使用它,你可以使用单参数的时间要求来引用它:

Alternately, if you're certain dojo/request has been loaded by the time you want to use it, you could use single-argument require to reference it:

require('dojo/request').post(...);

不过,这通常是不理想的,被视为一个黑客。

However, this is typically not ideal and seen as a hack.

也许介绍AMD模块教程将有助于更好地理解优化AMD的用法。

Perhaps the Introduction to AMD Modules tutorial would help to better understand optimal AMD usage.

这篇关于道场/请求不确定的,尽管需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆