1// jQuery.XDomainRequest.js 2// Author: Jason Moon - @JSONMOON 3// IE8+ 4if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) { 5 var httpRegEx = /^https?:\/\//i; 6 var getOrPostRegEx = /^get|post$/i; 7 var sameSchemeRegEx = new RegExp('^'+location.protocol, 'i'); 8 var htmlRegEx = /text\/html/i; 9 var jsonRegEx = /\/json/i; 10 var xmlRegEx = /\/xml/i; 11 12 // ajaxTransport exists in jQuery 1.5+ 13 jQuery.ajaxTransport('text html xml json', function(options, userOptions, jqXHR){ 14 // XDomainRequests must be: asynchronous, GET or POST methods, HTTP or HTTPS protocol, and same scheme as calling page 15 if (options.crossDomain && options.async && getOrPostRegEx.test(options.type) && httpRegEx.test(options.url) && sameSchemeRegEx.test(options.url)) { 16 var xdr = null; 17 var userType = (userOptions.dataType||'').toLowerCase(); 18 return { 19 send: function(headers, complete){ 20 xdr = new XDomainRequest(); 21 if (/^\d+$/.test(userOptions.timeout)) { 22 xdr.timeout = userOptions.timeout; 23 } 24 xdr.ontimeout = function(){ 25 complete(500, 'timeout'); 26 }; 27 xdr.onload = function(){ 28 var allResponseHeaders = 'Content-Length: ' + xdr.responseText.length + '\r\nContent-Type: ' + xdr.contentType; 29 var status = { 30 code: 200, 31 message: 'success' 32 }; 33 var responses = { 34 text: xdr.responseText 35 }; 36 try { 37 if (userType === 'html' || htmlRegEx.test(xdr.contentType)) { 38 responses.html = xdr.responseText; 39 } else if (userType === 'json' || (userType !== 'text' && jsonRegEx.test(xdr.contentType))) { 40 try { 41 responses.json = jQuery.parseJSON(xdr.responseText); 42 } catch(e) { 43 status.code = 500; 44 status.message = 'parseerror'; 45 //throw 'Invalid JSON: ' + xdr.responseText; 46 } 47 } else if (userType === 'xml' || (userType !== 'text' && xmlRegEx.test(xdr.contentType))) { 48 var doc = new ActiveXObject('Microsoft.XMLDOM'); 49 doc.async = false; 50 try { 51 doc.loadXML(xdr.responseText); 52 } catch(e) { 53 doc = undefined; 54 } 55 if (!doc || !doc.documentElement || doc.getElementsByTagName('parsererror').length) { 56 status.code = 500; 57 status.message = 'parseerror'; 58 throw 'Invalid XML: ' + xdr.responseText; 59 } 60 responses.xml = doc; 61 } 62 } catch(parseMessage) { 63 throw parseMessage; 64 } finally { 65 complete(status.code, status.message, responses, allResponseHeaders); 66 } 67 }; 68 // set an empty handler for 'onprogress' so requests don't get aborted 69 xdr.onprogress = function(){}; 70 xdr.onerror = function(){ 71 complete(500, 'error', { 72 text: xdr.responseText 73 }); 74 }; 75 var postData = ''; 76 if (userOptions.data) { 77 postData = (jQuery.type(userOptions.data) === 'string') ? userOptions.data : jQuery.param(userOptions.data); 78 } 79 xdr.open(options.type, options.url); 80 xdr.send(postData); 81 }, 82 abort: function(){ 83 if (xdr) { 84 xdr.abort(); 85 } 86 } 87 }; 88 } 89 }); 90}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.