views:

72

answers:

3

How can allow this page to run on IIS server... It does not work on localhost..... it works when I open it directly... It gives the error "it is not allowed...!

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

the Erorr: alt text

<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()">
+1  A: 

It's hard to tell what the error could be from the code you've given and without more details, such as the precise error message.

However, looking at your code, the most likely cause is that you are attempting a cross-site AJAX request. For security reasons, AJAX requests are allowed only to the same server that served the webpage. I.e. a script running on a webpage from example.com could only make AJAX requests to other pages at example.com. Requests to example1.com or example.net, for instance, would be forbidden.

You can read more about this here: http://en.wikipedia.org/wiki/Same_origin_policy

lonesomeday
I got what you mean. So what do you advice me, Can I fix it or another way to gather the data from xml services using jquery or javascript stuff...????
blgnklc
If the problem is indeed what lonesomeday is saying and you *have* to use AJAX, the best way would be to create a server side script that fetches the XML from the remote server. Then in your javascript you can call the new server side script (which in this case originates from the same server as your javascript).
captaintokyo
It is not indeed using javascript. I choose javascript since the existing page is coded with only html. Thats why I prefer javascript.
blgnklc
If you want to fetch data from a remote server, you will almost certainly have to do it on the server rather than on the client. The script would not need to be very complicated. You could potentially have a PHP script that read: "<?php echo file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; ?>". If you then stored this file on the same server as the calling page and called it with $.get it should work.
lonesomeday
+1  A: 

This error occurs because IE blocks the request to other sites (in your case www.micex.com). You can take a look at the jQuery API documentation, I find it very useful: http://api.jquery.com/jQuery.get/

Moreover, note this before the examples there:

Additional Notes:

  • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
  • If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method.
  • Script and JSONP requests are not subject to the same origin policy restrictions.

You may check this by adding try - catch block around the $.get(...); call and perform something additional in this case in the catch section or notify the user.

VasilP
+1  A: 

Permission denied because you requested something from a different remote domain. It's not allowed, in your case, you have to specify the datatype to jsonp. I've had similar problem my self. You would want to refer to jquery documents for more details

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

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

yangqi
@Could you please extend your answer with a detailed example or a direct link please..
blgnklc