IE8 jquery ajax get static resources error TypeError deny access

Source: Internet
Author: User

1. The code that is having the problem

 /*** * Request static HTML template * @param URL * @param $jqueryDiv: One of the four main div * @param templatehandle: Custom, used to use dot JS template function * @param callback: After implementing the template, the binding event * @param the return data of Templatedata:cia */Ajaxhtml: function (URL, $jqueryDiv, Templatehandle, Callback, TemplateData) {Xhr.ajaxhtmlcommon (URL, $jqueryDiv,NULL, Templatehandle, Callback, TemplateData); },/*** * Ajax request static HTML file * @param URL * @param $jqueryDiv * @param data * @param callback: callback function, upd After the Atehtml method executes * /Ajaxhtmlcommon: function (URL, $jqueryDiv, RequestData, Templatehandle, Callback, TemplateData) {        varArgument_length =arguments. length;varIshascallback = (Argument_length >4&& Callback &&typeofcallback = = =' function ');varOptions22 = {Url:url, type:"GET", timeout:18000, DataType:' HTML ', Success: function (HTML) {Updatehtml ($jqueryDiv, HTML, Templatehandle, TemplateData);/* var $formInput = jqueryobj.find (' Textarea:first ');//Allow textarea in subcontent to focus if ($formInput. length                 ! = 0) {//First determine if you can get to textarea $formInput. Get (0). focus (); }*/                if(Ishascallback)                {Callback ($JQUERYDIV, HTML); }}, Error: function (er) {                if(Er.statustext = =' Timeout ') {updatehtml ($jqueryDiv,"<div style= ' color:red ' > Connection server timed out! </div> "); }Else{varErrorMessage2;if(er.responsetext) {errorMessage2 = Er.responsetext; }Else{errorMessage2 = Er.statustext; } console.log (' ERROR: '+ ErrorMessage2);                Updatehtml ($jqueryDiv, ErrorMessage2, Templatehandle, TemplateData); }if(Ishascallback)                {Callback ($JQUERYDIV, er); }            }        };if(Argument_length >2&& RequestData! =NULL&& RequestData! =undefined) {options22.data = RequestData; Options22.type ="POST";    } $.ajax (OPTIONS22); }

Browser version: IE8
Get HTML template times wrong:

varfunction () {            xhr.ajaxHtml(‘cross_domain.html‘, $(‘#crossDiv‘nullnullnull);        }

Error message: TypeError denied access

2. Workaround:

(1) Increase in the head of JS file:

true;

(2) HTML file introduced JQuery.XDomainRequest.js

<!--[if IE 8]>    <script type="text/javascript"            src="jQuery.XDomainRequest.js"></script>    <![endif]-->

(3) Add static HTML template before:
< meta http-equiv= "Access-control-allow-origin" content= "*" >

Attention:
(1) The static HTML template should be added before, indicating that the server side supports cross-domain.
(2) Only IE8 have cross-domain access denied, so when introducing a third-party JS file, use <!–[if IE 8]>
(3) Jquery-1.11.1.js and above do not support IE8
JQuery.XDomainRequest.js See annex
Reference: Https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
Http://stackoverflow.com/questions/10232017/ie9-jquery-ajax-with-cors-returns-access-is-denied

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IE8 jquery ajax get static resources error TypeError deny access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.