需要帮助.js和AJAX [英] Help needed with .js and AJAX

查看:73
本文介绍了需要帮助.js和AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当使用AJAX和javascript时,

与我的服务器通话时出现以下错误:


来自 http://www.mydomain.com 的脚本被拒绝UniversalBrowserRead

特权。我正在使用firefox 1.5,这里的代码是

调用:


函数showConsumptionData(foodType){

var url =

''http://mydomain.com/platePyramid.do?foodType=''+

foodType +''& sysTime =''+ new Date( ).getTime();

if(window.XMLHttpRequest){

尝试{


netscape.security.PrivilegeManager.enablePrivilege (UniversalBrowserRead);

req = new XMLHttpRequest();

req.onreadystatechange = processSCRequest;

req.open(" GET",url,false);

req.send(null);

}

catch(e)

{

alert("(Mozilla) - " + e);

}

} else if(window.ActiveXObject) {

req = new ActiveXObject(" Microsoft.XMLHTTP");

req.onreadystatechange = processSCRequest;

req.open(" GET",url,false);

req.send(null);

}

}


.js文件包含在自己的文件中,由.hrml

文件调用。这会导致问题吗?我很难过。任何帮助将

赞赏

问候,


Steven H.

解决方案

只有使用权限的原因是跨域编码。


如果您需要它,那么您需要将代码添加到两个通常的地方。我用b $ b写了一个使用它的例子,
http://radio.javaranch.com/pascarell...=1120688860820


看看是否能给你带来光明问题。


Eric Pascarello

阿贾克斯在行动的合着者





sheadley写道:

来自 http://www.mydomain.com 被拒绝了UniversalBrowserRead
权限。我正在使用firefox 1.5,这里是被称为
的代码:

函数showConsumptionData(foodType){
var url =
''http:// mydomain.com/platePyramid.do?foodType=''+
foodType +''& sysTime =''+ new Date()。getTime();
if(window.XMLHttpRequest){
尝试{

netscape.security.PrivilegeManager.enablePrivilege(" UniversalBrowserRead");




您在这里调用enablePrivilege,但您的代码是不信任和

因此呼叫给出了所请求的特权消息

UniversalBrowserRead被拒绝。

HTML文档中的正常安全设置代码从HTTP加载
服务器无法启用权限,你需要使用

签名脚本。

为什么你需要那个打电话,或者为什么你认为你需要它?


如果带有脚本的HTML文档来自
http://www.mydomain.com/ 那么你的XMLHttpRequest对象应该能够

无需启用权限即可访问 www.mydomain.com 上的网址。

-


Martin Honnen
http://javaScript.FAQTs.com/


当我不使用以下代码时:

netscape.security.PrivilegeManager.enablePrivilege(" UniversalBrowserRead

");

我收到以下错误:


XMLHttpRequest .open()失败权限被拒绝。

我使用jboss和struts来服务这些页面会产生

的影响吗?


***通过开发人员指南 http://www.developersdex.com 发送* **

Hi all,
When using AJAX and javascript I get the following error when
talking to my server:

A script from http://www.mydomain.com was denied UniversalBrowserRead
privileges. I am using firefox 1.5 and here is the code that is being
called:

function showConsumptionData(foodType) {
var url =
''http://mydomain.com/platePyramid.do?foodType='' +
foodType+''&sysTime=''+new Date().getTime();
if (window.XMLHttpRequest) {
try {

netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead");
req = new XMLHttpRequest();
req.onreadystatechange = processSCRequest;
req.open("GET", url, false);
req.send(null);
}
catch (e)
{
alert("(Mozilla)-"+e);
}
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = processSCRequest;
req.open("GET", url, false);
req.send(null);
}
}

The .js files is contained in its own file, being called by the .hrml
file. Could this be causing the problem? I am stumped. Any help would
be appreciated
Regards,

Steven H.

解决方案

Only reason to use the Privilege is for cross domain coding.

If you need it then you need to add the code in two places normally. I
wrote an example using it awhile back,
http://radio.javaranch.com/pascarell...=1120688860820

See if that gives you any light into the problem.

Eric Pascarello
Coauthor of Ajax In Action




sheadley wrote:

A script from http://www.mydomain.com was denied UniversalBrowserRead
privileges. I am using firefox 1.5 and here is the code that is being
called:

function showConsumptionData(foodType) {
var url =
''http://mydomain.com/platePyramid.do?foodType='' +
foodType+''&sysTime=''+new Date().getTime();
if (window.XMLHttpRequest) {
try {

netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead");



You are calling enablePrivilege here but your code is not trusted and
therefore the call gives that message that the requested privilege
UniversalBrowserRead was denied.
With normal security settings code in a HTML document loaded from a HTTP
server is not not able to enable privileges, you would need to use
signed script.
Why do you need that call, or why do you think you need it?

If your HTML document with the script comes from
http://www.mydomain.com/ then your XMLHttpRequest object should be able
to access URLs on www.mydomain.com without any need to enable privileges.
--

Martin Honnen
http://JavaScript.FAQTs.com/


when I don''t use the following code:
netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead
");
I get the following error:

XMLHttpRequest.open() failed permission denied.
I am using jboss and struts to server up these pages would that have an
impact??

*** Sent via Developersdex http://www.developersdex.com ***


这篇关于需要帮助.js和AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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