2015-11-08 54 views
0

strophe.flxhr.jsstrophe.flxhr.js - 類型錯誤:this.func.prependArg不是一個函數

/* flXHR plugin 
** 
** This plugin implements cross-domain XmlHttpRequests via an invisible 
** Flash plugin. 
** 
** In order for this to work, the BOSH service *must* serve a 
** crossdomain.xml file that allows the client access. 
** 
** flXHR.js should be loaded before this plugin. 
*/ 

Strophe.addConnectionPlugin('flxhr', { 
    init: function() { 
     // replace Strophe.Request._newXHR with new flXHR version 
     // if flXHR is detected 
     if (flensed && flensed.flXHR) { 
      Strophe.Request.prototype._newXHR = function() { 
       var xhr = new flensed.flXHR({ 
        autoUpdatePlayer: true, 
        instancePooling: true, 
        noCacheHeader: false}); 
       xhr.onreadystatechange = this.func.prependArg(this); 

       return xhr; 
      }; 
     } else { 
      Strophe.error("flXHR plugin loaded, but flXHR not found." + 
          " Falling back to native XHR implementation."); 
     } 
    } 
}); 

這是一本書,從中我想學習編程XMPP使用JavaScript和jQuery提供的代碼。它也使用strophe.jsflXHR.jsstrophe.flxhr.js被用作主應用程序中的腳本文件。但是,在我的FireFox瀏覽器中運行應用程序時,Web控制檯給我提供了錯誤TypeError: this.func.prependArg is not a function。另外我正在使用WebStorm IDE,它顯示Unresolved function or method prependArg()。但根據這本書,這應該運行。我在做什麼錯?

請幫忙。謝謝。

回答

0

顯然,strophe.flxhr.js文件出現故障。這是一個非常舊的版本(6歲)。這個在github here有一個新版本。 代碼有一些細微的變化,這是行得通的。 Web控制檯沒有引發錯誤。這是新代碼:

strophe.flxhr.js

/* flXHR plugin 
** 
** This plugin implements cross-domain XmlHttpRequests via an invisible 
** Flash plugin. 
** 
** In order for this to work, the BOSH service *must* serve a 
** crossdomain.xml file that allows the client access. 
** 
** flXHR.js should be loaded before this plugin. 
*/ 

Strophe.addConnectionPlugin('flxhr', { 
    init: function (conn) { 
     // replace Strophe.Request._newXHR with new flXHR version 
     // if flXHR is detected 
     if (flensed && flensed.flXHR) { 
      Strophe.Request.prototype._newXHR = function() { 
       var xhr = new flensed.flXHR({ 
        autoUpdatePlayer: true, 
        instancePooling: true, 
        noCacheHeader: false, 
        onerror: function() { 
         conn._changeConnectStatus(Strophe.Status.CONNFAIL, 
                "flXHR connection error"); 
         conn._onDisconnectTimeout(); 
        }}); 
       xhr.onreadystatechange = this.func.bind(null, this); 

       return xhr; 
      }; 
     } else { 
      Strophe.error("flXHR plugin loaded, but flXHR not found." + 
          " Falling back to native XHR implementation."); 
     } 
    } 
}); 

EDIT: From the developer of this script, Jack Moffitt : "This code no longer works. strophe.flxhr.js just makes some testing easier as it relaxes the CORS requirement by using Flash instead. Most things support CORS natively now, so it is probably not needed anyway. It doesn't provide any APIs or anything that are needed by the example code; it's purely an alternate implementation of XMLHttpRequest. If you can make the newer version work, then use it.". Here is the conversation.

相關問題