2015-11-08 1 views
0

strophe.flxhr.jsstrophe.flxhr.js - TypeError: 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.js и flXHR.js. strophe.flxhr.js используется как файл сценария в главном приложении. Но во время запуска приложения в моем браузере FireFox веб-консоль дает мне ошибку TypeError: this.func.prependArg is not a function. Также я использую WebStorm IDE, и он показывает Unresolved function or method prependArg(). Но, согласно книге, это должно сработать. Что я делаю неправильно?

Пожалуйста, помогите. Спасибо.

ответ

0

По-видимому, произошла ошибка в файле strophe.flxhr.js. Это была очень старая версия (6 лет). В github here есть новая версия. Существует небольшое изменение в коде, и это работает. Веб-консоль не вызывает ошибок. Это новый код:

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.