【问题标题】:jquery method is not allowed不允许使用 jquery 方法
【发布时间】:2011-04-12 22:35:09
【问题描述】:

如何让这个页面在 IIS 服务器上运行... 它在本地主机上不起作用......当我直接打开它时它工作......它给出错误“它是不允许的......!

The working Example..! I want this..""

错误:

<html>
<head>

<script src="jquery.js" type="text/javascript" language="javascript"></script>
<script src="jquery.xml2json.js" type="text/javascript" language="javascript"></script>


<script>
function sayHello(msg)
{

   alert(msg);
}

function dcSetRate(obj,value){

document.getElementById(obj).value = value.toFixed(4);

}

function dcSet(obj,value){

document.getElementById(obj).value = value;

}

(function(usedUrl) {
   //All currencies quoted against the euro 
    var fetchService = function() {

    /*USD/RUB
EUR/RUB

USD/EUR
USD/TL*/
                $.get('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml', function(xml) {
                      var jsonObj = $.xml2json(xml);

                        //alert(jsonObj.Cube.Cube.Cube[0]["currency"] + 2);
                        var usd=jsonObj.Cube.Cube.Cube[0]["rate"];
                        var rub=jsonObj.Cube.Cube.Cube[16]["rate"];
                        var eur= 1 //jsonObj.Cube.Cube.Cube[1]["rate"];
                        var ytl=jsonObj.Cube.Cube.Cube[17]["rate"];

                        var usd_rub= rub/usd;
                        var eur_rub =rub/eur;
                        var usd_eur = eur/usd;
                        var usd_ytl= ytl/usd;
                        dcSetRate("USD_RUB",usd_rub);
                        dcSetRate("EUR_RUB",eur_rub);
                        dcSetRate("USD_EUR",usd_eur);
                        dcSetRate("USD_YTL",usd_ytl);
                }); 
getMicex();
                // assuming your elements are <img>
                document.getElementById("text1").value = getDt();
                // if not you could also set the background (or backgroundImage) css property
                // document.getElementById(elements.shift()).style.background = "url(" + images.shift() + ")";
                ///sayHello(usedUrl);

            setTimeout(fetchService, 10500);

        }

    window.onload = fetchService;
}(['URL URL']))

function getMicex(){

$.get('http://www.micex.com/issrpc/marketdata/stock/index/daily/short/result.xml', function(xml) {
                      var jsonObj = $.xml2json(xml);
                      var indexValue = jsonObj.row["CURRENTVALUE"];
                     dcSet("Micex",indexValue);
                      });
}

function getDt(){
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (minutes < 10){
minutes = "0" + minutes
}
var ama;
if(hours > 11){
ama ="PM";
} else {
ama ="AM";
}
 return hours + ":" + minutes + " : " + seconds + " " + ama;
}
</script>
</head>
<body>
 <input type="text" name="fname" id="text1"/><br/>
   USD_RUB<input type="text" name="fname" id="USD_RUB"/><br/>
   EUR_RUB <input type="text" name="fname" id="EUR_RUB"/><br/>
    USD_EUR <input type="text" name="fname" id="USD_EUR"/><br/>
    USD_YTL  <input type="text" name="fname" id="USD_YTL"/><br/>
        Micex<input type="text" name="fname" id="Micex"/><br/>
</body>
</html onLoad="sayHello()">

【问题讨论】:

  • 你应该给出确切的错误信息,总是,它的存​​在是有原因的。

标签: php asp.net jquery html iis


【解决方案1】:

如果没有更多详细信息(例如准确的错误消息),很难从您提供的代码中判断错误可能是什么。

但是,查看您的代码,最可能的原因是您正在尝试跨站点 AJAX 请求。出于安全原因,AJAX 请求只允许发送到为网页提供服务的同一服务器。 IE。在 example.com 网页上运行的脚本只能向 example.com 上的其他页面发出 AJAX 请求。例如,对 example1.com 或 example.net 的请求将被禁止。

您可以在此处阅读更多信息:http://en.wikipedia.org/wiki/Same_origin_policy

【讨论】:

  • 我明白你的意思。那么你对我有什么建议,我可以修复它还是以其他方式使用 jquery 或 javascript 的东西从 xml 服务收集数据......????
  • 如果问题确实是 lonesomeday 所说的并且您必须使用 AJAX,最好的方法是创建一个从远程服务器获取 XML 的服务器端脚本.然后在您的 javascript 中,您可以调用新的服务器端脚本(在这种情况下,它来自与您的 javascript 相同的服务器)。
  • 确实没有使用 javascript。我选择 javascript,因为现有页面仅使用 html 进行编码。这就是为什么我更喜欢 javascript。
  • 如果您想从远程服务器获取数据,您几乎肯定必须在服务器上而不是在客户端上进行。脚本不需要非常复杂。您可能有一个 PHP 脚本,其内容为:“ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; ?>”。如果您随后将此文件存储在与调用页面相同的服务器上并使用 $.get 调用它,则它应该工作。
【解决方案2】:

出现此错误是因为 IE 阻止了对其他站点的请求(在您的情况下为 www.micex.com)。 您可以查看 jQuery API 文档,我觉得它非常有用: http://api.jquery.com/jQuery.get/

此外,请在示例之前注意这一点:

补充说明:

  • 由于浏览器安全限制,大多数“Ajax”请求都是 遵循同源政策;这 请求无法成功检索 来自不同域的数据, 子域或协议。
  • 如果使用 jQuery.get() 的请求返回错误代码,它将失败 除非脚本也有 调用全局 .ajaxError() 方法。
  • 脚本和 JSONP 请求不受同源策略的约束 限制。

您可以通过在 $.get(...); 周围添加 try - catch 块来检查这一点。在这种情况下,请在 catch 部分调用并执行其他操作或通知用户。

【讨论】:

    【解决方案3】:

    权限被拒绝,因为您从不同的远程域请求了某些内容。这是不允许的,在您的情况下,您必须将数据类型指定为 jsonp。我自己也有类似的问题。更多详情请参考 jquery 文档

    http://api.jquery.com/jQuery.ajax/

    http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

    【讨论】:

    • @能否请您通过详细示例或直接链接扩展您的答案..
    猜你喜欢
    • 2016-01-23
    • 1970-01-01
    • 2012-04-30
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    相关资源
    最近更新 更多