2015-12-23 13 views
6

नहीं कहा जा रहा है माइक्रोसॉफ्ट एज में, एक जीईटी अनुरोध नहीं चल रहा है। मैंने AJAX अनुरोध को चलाने के बिंदु पर कोड के माध्यम से कदम रखा है, और कॉलबैक में ब्रेकपॉइंट सेट किया है। हालांकि, कोड कॉलबैक तक कभी नहीं पहुंचता है।माइक्रोसॉफ्ट एज easyXDM ("संदेश") ईवेंट को

मेरे पास कॉलबैक के साथ पहले से ही .then() और .fail() सेटअप है, और कॉलबैक के साथ .done() और .always() जोड़ने का प्रयास किया है, लेकिन कॉलबैक में कोई भी कोड चल रहा है।

फिर मैंने देव-टूल्स में नेटवर्क टैब की जांच की, और मुझे बिल्कुल अनुरोध नहीं मिला। ऐसा लगता है कि एज कुछ कारणों से अनुरोध को फायर नहीं कर रहा है।

request = function(options, resolveScope) { 
    var deferred = $.Deferred(); 
    corsHandler.makeRequest(options) 
     .done(this._wrap(function(response) { 
      deferred.resolveWith(resolveScope, [response]); //never gets here 
     }, this)) 
     .fail(this._wrap(function(response) { 
      deferred.rejectWith(resolveScope, [response]); //never gets here 
     }, this)); 
    return deferred; 
} 

यह ऊपर अनुरोध फ़ंक्शन को कॉल करता है।

ajaxFunc = function(data, scope) { 
    return request({ 
     url: '/path/to/server', 
     internalUrl: true, 
     method: 'GET', 
     datatype: 'json', 
     data: data 
    }, scope); 
} 

यह अनुरोध करने के लिए उपयोग किया गया कार्यान्वयन है।

(function() { 
    // set data var 
    return ajaxFunc(data, self) 
     .then(function(res) { console.log(res); }) //never gets here 
     .done(function(res) { console.log(res); }) //never gets here 
     .fail(function(res) { console.log(res); }) //never gets here 
     .finally(function(res) { console.log(res); }) //never gets here 
})(); 

यहां कॉर्स सामान है। (मैं इस बारे में एक पूरी बहुत कुछ पता नहीं।)

corsHandler.makeRequest = function(options) { 
     // resolve default options 
     _.defaults(options, { 
      xhr:  null, 
      corsUrl: null, 
      url:  null, 
      method:  'GET', 
      data:  {}, 
      success: function() {}, 
      error:  function() {}, 
      terminate: false, 
      binary:  false, 
      headers: {}, 
      internalUrl: false, 
      datatype: '' 
     }); 
     // if url is internal, create absolute url from relative url 
     if (options.internalUrl) { 
      options.url = this.createAbsoluteInternalUrl(options.url); 
     } 

     // resolve cors url or proxy url 
     options.corsUrl = options.corsUrl || this.getCorsUrl(options.url); 
     if (!options.corsUrl) { 
      options.url  = this.getProxyUrl(options.url); 
      options.corsUrl = this.getCorsUrl(options.url); 
     } 

     // create xhr 
     if (!options.xhr && options.corsUrl) { 
      options.xhr = this.createXhr(options.corsUrl); 
     } 

     // create cleanup procedure 
     var cleanUpAfterRequest = $.proxy(function() { 
      if (options.terminate) { 
       options.xhr.destroy(); 
       this._removeCacheXhr(options.corsUrl); 
      } 
     }, this); 

     // prepare deffered object 
     var deferred = $.Deferred(); 
     deferred 
      .done(function() { 
       if (options.success) { 
        options.success.apply(null, Array.prototype.slice.call(arguments)); 
       } 
      }) 
      .fail(function() { 
       if (options.error) { 
        options.error.apply(null, Array.prototype.slice.call(arguments)); 
       } 
      }); 

     // make actual request 
     if (!options.xhr) { 
      throw 'corsHandler: xhr object was not created or defined to make request'; 
      // this does not happen 
     } 
     options.xhr.request(
      { 
       url: options.url, 
       method: options.method, 
       data: options.data, 
       binary: options.binary, 
       headers: options.headers, 
       datatype: options.datatype 
      }, 
      function() { 
       deferred.resolve.apply(null, Array.prototype.slice.call(arguments)); 
       cleanUpAfterRequest(); 
      }, 
      function() { 
       deferred.reject.apply(null, Array.prototype.slice.call(arguments)); 
       cleanUpAfterRequest(); 
      } 
     ); 
     return deferred; 
    } 

अद्यतन

ऐसा लगता है कि इस मुद्दे की तरह easyXDM में है। waitForReady() किनारे पर on(window, "message", waitForReady) फायरिंग नहीं कर रहा है। मैं इस मुद्दे को और अधिक देख रहा हूं।

easyXDM स्निपेट:

targetOrigin = getLocation(config.remote); 
    if (config.isHost) { 
     // add the event handler for listening 
     var waitForReady = function(event){ 
      if (event.data == config.channel + "-ready") { 
       // replace the eventlistener 
       callerWindow = ("postMessage" in frame.contentWindow) ? frame.contentWindow : frame.contentWindow.document; 
       un(window, "message", waitForReady); 
       on(window, "message", _window_onMessage); 
       setTimeout(function(){ 
        pub.up.callback(true); 
       }, 0); 
      } 
     }; 
     on(window, "message", waitForReady); 

     // set up the iframe 
     apply(config.props, { 
      src: appendQueryParameters(config.remote, { 
       xdm_e: getLocation(location.href), 
       xdm_c: config.channel, 
       xdm_p: 1 // 1 = PostMessage 
      }), 
      name: IFRAME_PREFIX + config.channel + "_provider" 
     }); 
     frame = createFrame(config); 
    } 

ऊपर टुकड़ा चलाता है, लेकिन waitForReady विधि कभी नहीं कहा जाता है। एकमात्र ब्राउज़र जिसे इसे नहीं कहा जाता है वह एज है (आईई 8 +, क्रोम, सफारी, एफएफ, और मोबाइल क्रोम/सफारी में काम करता है)।

+0

क्या विशेषता नहीं है डेटा टाइप टाइप करें? ऐसा मत सोचो कि यह मुद्दा होगा, लेकिन सही करने के लायक है। मैंने अतीत में आग लगने में अनुरोधों का अनुभव किया है जब उस गलती को –

+2

को 'console.log'' रखने के लिए कोई दिक्कत नहीं होगी, बस हर जगह लगभग '.done' '.fail'' .then' चल रहा है यह देखने के लिए। – SoluableNonagon

+0

@AntonioManente इनपुट के लिए धन्यवाद, मैं उसमें देख लूंगा। – Jacques

उत्तर

0

यह पता चला कि एक आवश्यक "हैक" था जिसे पिछले डेवलपर ने easyXDM के हमारे कार्यान्वयन में लिखा था।

easyXDM के हमारे कार्यान्वयन में, हमें आईई पर Window ऑब्जेक्ट अपडेट करना पड़ा क्योंकि हमारा ऐप आईफ्रेम में लॉन्च हुआ था। चूंकि एज तकनीकी रूप से IE का संस्करण नहीं है, इसलिए हमारा परीक्षण विफल हो रहा था, इसलिए कोड window को 0xको easyXDM के संदर्भ में अद्यतन करने के लिए नहीं चल रहा था।

हम IE का पता लगाने के लिए typeof document.documentMode === 'number' का उपयोग कर रहे हैं, लेकिन document.documentMode एज में अपरिभाषित है, इसलिए हमने navigator.userAgent एज के लिए चेक जोड़ा।

इसने इस मुद्दे को हल किया।

संबंधित मुद्दे