Zināšanu bāze

Microsoft IE 8 XDomainRequest

Sveicināti,

Turpinot iesākto tēmu par Microsoft IE 8 jaunumiem no programmētāja stata punkta. Šoreiz, par iespēju veikt asinhronos vaicājumus uz citu domēnu no JavaScript. Līdz nesenam laikam, modernajos pārlūkos pastāvēja ierobežojums, veidot vaicājumus tikai sava domēna ietvaros. Drīzumā šis ierobežojums tiks likvidēts. Bet par visu pēc kārtas.

IE 8 pārlūkā no JavaScript ir pieejams jauns objekts XDomainRequest. Objekts nodrošina šo te komunikāciju starp domēniem. Apskatīsim, kā tas darbojās uz piemēra

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script type="text/javascript">

        function getData() {

            var xdr = new XDomainRequest();
            xdr.open("get", "http://www.getdate.com/getdate.aspx");

            xdr.onload = function() {
                document.getElementById('content').innerHTML = 
toStaticHTML(xdr.responseText
); } xdr.send(); } </script> </head> <body> <button onclick="getData();"> Get date</button> <div id="content"></div> </body> </html>

Uzrakstīju nelieku HTML kodu, pēc noklusējuma uz ekrāna parādās poga ar tekstu “Get date”. Nospiežot pogu, tiek izsaukta metode “getData”. Tie izveidots objekts XDomainRequest. Ar “open” metodes palīdzību, tiek izveidots savienojums ar citu domēna serveri. Parakstāmies uz notikumu “onload”, saņemtās atbildes saturu ievietojam elementā DIV ar nosaukumu “content”. Šinī vietā jāpiemin jauna IE 8 metode “toStaticHTML”, ar tās palīdzību kods tiek pasargāts no iespējamās JavaScript injekcijas(Injection). Vienkārši sakot, no satura tiek izmesti visi skripti un skriptu izsaukumi. Manu kodu noslēdz metodes “send” izsaukums. Tātad pieprasījums ir nosūtīts. No klienta puses tas arī vienkāršā gadījumā arī viss.

Servera pusē, servera atbildei ir jāpievieno iesākums (Header)  (Response.AddHeader("Access-Control-Allow-Origin", "*"). Tādā veidā tiek pateikt, ka tiek atbalstīts starp domēnu izsaukums. Zvaigznītes vietā var norādīt arī konkrētu domēnu.

Pielikumā pievienoju Visual Studio projektu, lai to notestētu uz sava datora.

P.S. Pirms palaist piemēru modificējies Windows host failu, lai domēns www.getdate.com tiktu piesaistīts localhost.

 

Cerams noderēs!


Posted Apr 08 2009, 06:17 PM by andrejs.mamontovs

Comments

m wrote re: Microsoft IE 8 XDomainRequest
on 04-08-2009 22:26

Ko w3 par šo saka/teiks?

andrejs.mamontovs wrote re: Microsoft IE 8 XDomainRequest
on 04-09-2009 9:39

Šī iespēja tiek atbalstīta, jau tagad jaunākajā FireFox betā ir iepēja arī veikt šādus pieprasījumus

Kā arī ir noteikt drafts dev.w3.org/.../access-control par piekļuves kontroli

viesis wrote re: Microsoft IE 8 XDomainRequest
on 09-20-2010 15:34

Kādas domas par šo? :) plugins.jquery.com/.../C4PCJsonRPC

buy google +1 wrote re: Microsoft IE 8 XDomainRequest
on 03-23-2012 5:06

HWCEKT Im obliged for the blog post.Thanks Again. Want more.

Seo Services wrote re: Microsoft IE 8 XDomainRequest
on 08-09-2012 7:30

nzzRkr I truly appreciate this blog.Much thanks again. Really Great.

cheap bookmarking service wrote re: Microsoft IE 8 XDomainRequest
on 09-12-2012 11:18

eMaOnW Im thankful for the article post.Really looking forward to read more. Keep writing.

bookmarking submission wrote re: Microsoft IE 8 XDomainRequest
on 10-07-2012 13:03

kn1SJH Thanks for sharing, this is a fantastic post.Really thank you! Fantastic.

cheap seo services wrote re: Microsoft IE 8 XDomainRequest
on 11-09-2012 8:17

B7lGCG Thanks-a-mundo for the blog.Much thanks again. Keep writing.

nike free 3.0 v2 wrote re: Microsoft IE 8 XDomainRequest
on 11-20-2012 4:09

Don't discuss about it your favorite joy and happiness to a single a lesser amount of successful as opposed to on your own.

[url=www.nikeschuhedamenherren.com/nike-free-30-v2-damen-running-schuhe-schwarz-blau-p-978.html]nike free 3.0 v2[/url]

<a href="www.nikeschuhedamenherren.com/nike-free-30-v2-damen-running-schuhe-schwarz-blau-p-978.html" title="nike free 3.0 v2">nike free 3.0 v2</a>

Seo Service wrote re: Microsoft IE 8 XDomainRequest
on 11-28-2012 11:09

JBte2w Wow, great post.Much thanks again. Keep writing.

viagra online wrote re: Microsoft IE 8 XDomainRequest
on 01-10-2013 10:13

qfh2Hi Say, you got a nice post.Really thank you! Keep writing.

social bookmarking link building wrote re: Microsoft IE 8 XDomainRequest
on 01-19-2013 2:49

KwB44Y wow, awesome post.Really thank you! Really Great.

archeage gold wrote re: Microsoft IE 8 XDomainRequest
on 02-26-2013 23:42

Well I definitely enjoyed reading it. This information provided by you is very practical for good planning. archeage gold www.cheap-archeage-gold.com

Jordan 10 wrote re: Microsoft IE 8 XDomainRequest
on 03-04-2013 7:19

Where exactly might a bonded relationship without requiring take pleasure in, it will be take pleasure in without requiring a bonded relationship. Jordan 10 http://www.nike44.com/

casquette supreme wrote re: Microsoft IE 8 XDomainRequest
on 03-14-2013 15:23

Assume‘tonne waste product your energy and time for a guy/females,what individual isn‘tonne able to waste product any instance on you. casquette supreme http://www.b44.fr/

Social bookmarks wrote re: Microsoft IE 8 XDomainRequest
on 03-23-2013 9:16

2SFa9d I am so grateful for your article. Really Cool.

coach outlet locations wrote re: Microsoft IE 8 XDomainRequest
on 04-07-2013 0:55

If you want some sort of information systems of our very well worth, volume relations. coach outlet locations www.coachfactoryoutlet99.com

coachfactoryoutlet33.com wrote re: Microsoft IE 8 XDomainRequest
on 04-07-2013 5:32

Those that is likely to maintain your solution starting from an opponent, inform the software due to this cause companion.

tee shirt homme wrote re: Microsoft IE 8 XDomainRequest
on 04-15-2013 9:18

Really enjoy, affinity, respect for authority, tend not to link most people over a well-known hate with issue. tee shirt homme http://www.spartooo.fr/

Add a Comment

(obligāts)  
(brīvizvēles)
(obligāts)  
Remember Me?