mui.ajax.5+.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * 5+ ajax
  3. */
  4. (function($) {
  5. var originAnchor = document.createElement('a');
  6. originAnchor.href = window.location.href;
  7. $.plusReady(function() {
  8. $.ajaxSettings = $.extend($.ajaxSettings, {
  9. xhr: function(settings) {
  10. if (settings.crossDomain) { //强制使用plus跨域
  11. return new plus.net.XMLHttpRequest();
  12. }
  13. //仅在webview的url为远程文件,且ajax请求的资源不同源下使用plus.net.XMLHttpRequest
  14. if (originAnchor.protocol !== 'file:') {
  15. var urlAnchor = document.createElement('a');
  16. urlAnchor.href = settings.url;
  17. urlAnchor.href = urlAnchor.href;
  18. settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host);
  19. if (settings.crossDomain) {
  20. return new plus.net.XMLHttpRequest();
  21. }
  22. }
  23. if ($.os.ios && window.webkit && window.webkit.messageHandlers) { //wkwebview下同样使用5+ xhr
  24. return new plus.net.XMLHttpRequest();
  25. }
  26. return new window.XMLHttpRequest();
  27. }
  28. });
  29. });
  30. })(mui);