Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2012, 01:18 PM   PM User | #1
ridan
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ridan is an unknown quantity at this point
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,
ridan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:31 AM.


Advertisement
Log in to turn off these ads.