XDomainRequest
lotstyl non è online. Ultima attività: 29/08/2008 13.57.11lotstyl
Inserito il: 24 luglio 2008 00.07
76 messaggi dal 06 giu 2005 Istalla Microsoft Silverlight!
Sto giocando un pò con XDomainRequest utilizzando ie 8 beta 1, e nelle mie prove in locale tutto è sempre filato liscio.
ho allora provato a mettere i miei test in rete, ma ad ogni richiesta cross-site ottengo un errore dell'oggetto XDomainRequest. Problema di permessi? Problema di codice?

Ecco il codice della pagina che implementa l'oggetto:


<html>
<script type="text/javascript">
    var xdr;

    function readdata()
    {
        var dRes = document.getElementById('dResponse');
        dRes.innerText = xdr.responseText;
        alert("Content-type: " + xdr.contentType);
        alert("Length: " + xdr.responseText.length);
    }
    
    function err()
    {
        alert("XDR onerror");
    }
    function timeo()
    {
        alert("XDR ontimeout");
    }
    function loadd()
    {
        alert("XDR onload");
        alert("Got: " + xdr.responseText);
    }
    function progres()
    {
        alert("XDR onprogress");
        alert("Got: " + xdr.responseText);
    }

    function stopdata()
    {
        xdr.abort();
    }

    function mytest()
    {
        var url = document.getElementById('tbURL');
        var timeout = document.getElementById('tbTO');
        if (window.XDomainRequest)
        {
            xdr = new XDomainRequest();
            if (xdr)
            {
                xdr.onerror = err;
                xdr.ontimeout = timeo;
                xdr.onprogress = progres;
                xdr.onload = loadd;

                xdr.timeout = tbTO.value;
                xdr.open("get", tbURL.value);
                xdr.send();
            }
            else
            {
                alert('Failed to create');
            }
        }
        else
        {
            alert('XDR doesnt exist');
        }
    }
</script>
<body>
    XDomainRequest<br>
    <input type=text id=tbURL value='http://www.contoso.com/xdr.txt' style="width:300px"><br>
    <input type=text id=tbTO value='10000'><br>
    <input type=button onclick=mytest() value="Get">&nbsp;&nbsp;&nbsp;
    <input type=button onclick=stopdata() value="Stop">&nbsp;&nbsp;&nbsp;
    <input type=button onclick=readdata() value="Read">

    <br>
    <div id='dResponse'></div>
</body>
</html>

RE: XDomainRequest
makbox non è online. Ultima attività: 26/08/2008 14.26.48makbox
Inserito il: 24 luglio 2008 09.02
20 messaggi dal 24 mag 2002 Istalla Microsoft Silverlight!
Credo tu abbia commesso un errore nell'assegnazione della URL e del timeout.
Nella function mytest() prima assegni

var url = document.getElementById('tbURL');
var timeout = document.getElementById('tbTO');


ma poi usi

xdr.timeout = tbTO.value;
xdr.open("get", tbURL.value);


da quanto vedo dovresti fare

xdr.timeout = timeout.value;
xdr.open("get", url.value);


Marco

RE: XDomainRequest
lotstyl non è online. Ultima attività: 29/08/2008 13.57.11lotstyl
Inserito il: 24 luglio 2008 10.35
76 messaggi dal 06 giu 2005 Istalla Microsoft Silverlight!
mmm...ho provato a cambiare il codice ma niente da fare, non sembra essere questo.
sono sempre più convinto che sia una questione di permessi.

grazie comunque
RE: XDomainRequest
makbox non è online. Ultima attività: 26/08/2008 14.26.48makbox
Inserito il: 24 luglio 2008 11.02
20 messaggi dal 24 mag 2002 Istalla Microsoft Silverlight!
Purtroppo non ho sotto mano IE8 e non posso fare delle prove.
Se riesci a trovare la soluzione postala che potrebbe essere utile in futuro.

Marco.

RE: XDomainRequest
lotstyl non è online. Ultima attività: 29/08/2008 13.57.11lotstyl
Inserito il: 24 luglio 2008 12.31
76 messaggi dal 06 giu 2005 Istalla Microsoft Silverlight!
Allora, cercando in rete ho trovato su MSDN che:



Cross-domain requests require mutual consent between the webpage and the server. You can initiate a cross-domain request in your webpage by creating an XDomainRequest object off the window object, and opening a connection to a particular domain. The browser will request data from the domain's server by sending an "XDomainRequest: 1" header. It will only complete the connection if the server responds with an "XDomainRequestAllowed" header with the value "1" (for true). For example, a server's asp page may include the response header: "Response.AppendHeader("XDomainRequestAllowed","1");".

XDR requires a header to be returned by a server. Any server-side technology that supports adding response headers may be used.


http://msdn.microsoft.com/en-us/library/cc288108(VS.85).aspx



Ho quindi provato a richiedere una pagina ASPX che impostasse l'header in modo corretto. Questo è il codice della pagina asp.net che XDomainRequest richiede:


<%  
  Response.AppendHeader("XDomainRequestAllowed", "1")
  Response.Write("Hello World!")
%>


Ovviamente con .net posso gestire le risposte e restituire non solo una semplice frase "Hello World" ma anche un file ecc.

Ciao e grazie.

Vai a:
Torna al forum |   Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.


maltra - 711 pt
vladimiro - 471 pt
fabrica - 180 pt

Ultimi vincitori: fabrica, vladimiro, PeppeDotNet

Iscriviti anche tu e raccogli punti. Questo mese in palio VS 2008 + Windows Server 2008, ReShaper e 1 ebook!



COMMUNITY
ULTIMI MESSAGGI


IN EVIDENZA
MISC
Powered by .db Forums