CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   Override XMLHTTPRequest Calls (http://www.codingforums.com/showthread.php?t=276253)

ridan 10-12-2012 01:18 PM

Override XMLHTTPRequest Calls
 
I'm trying to override XMLHTTPRequest behaviour in order to delegate Ajax requests to a phonegap plugin in case of a native app (Which will handle https certificate authentication challenge).

In case the application is running in native container,
  • Cancel current HTTP call
  • Call the phonegap plugin in order to execute HTTP call
  • Receive HTTP response
  • Trigger an event in current XMLHttpRequest instance with http response elements
My apps must run on a native et web context using the same source code. Developers can do Ajax calls seamlessly.

Here is a sample code for what I'm trying to do:

Code:

XMLHttpRequest.prototype.send = function() {
    var me = this;
    me.abort();
    cordova.exec(function(httpresult) {           
        // Query success
        // httpresult object contains http response headers and content
        // How can onreadystatechange be triggered ???
        me.onreadystatechange(httpresult);
    }, function(httpresult) {
        // Query failure
    }, "QueryPlugin", "query", [{
        url: me.url,
        method: me.method,
        data: me.data
        // other http query params
    }]);
}

I don't know how to pass http headers and content properly to the current XMLHttpRequest instance and how to trigger onreadystatechange method.

If you have any ideas. Thanks in advance,


All times are GMT +1. The time now is 06:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.