123456789101112131415161718192021222324252627282930 |
- /**
- * 5+ ajax
- */
- (function($) {
- var originAnchor = document.createElement('a');
- originAnchor.href = window.location.href;
- $.plusReady(function() {
- $.ajaxSettings = $.extend($.ajaxSettings, {
- xhr: function(settings) {
- if (settings.crossDomain) { //强制使用plus跨域
- return new plus.net.XMLHttpRequest();
- }
- //仅在webview的url为远程文件,且ajax请求的资源不同源下使用plus.net.XMLHttpRequest
- if (originAnchor.protocol !== 'file:') {
- var urlAnchor = document.createElement('a');
- urlAnchor.href = settings.url;
- urlAnchor.href = urlAnchor.href;
- settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host);
- if (settings.crossDomain) {
- return new plus.net.XMLHttpRequest();
- }
- }
- if ($.os.ios && window.webkit && window.webkit.messageHandlers) { //wkwebview下同样使用5+ xhr
- return new plus.net.XMLHttpRequest();
- }
- return new window.XMLHttpRequest();
- }
- });
- });
- })(mui);
|