Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to get actual data from e

Hello,

I am fetching some data in app.js from my webserver and send to my webview using fireevent.but in web view how that data is to be fetched frome e.

Code App.js:
Titanium.App.fireEvent("some_event_name",this.responseText);

Code webview.html:

<script>
Titanium.App.addEventListener("some_event_name",function(e)
{

 alert("hi"+e.data);

});

</script>

how that data is to be fetched?

— asked March 27th 2010 by vikas khairnar
  • titanium.app.addeventlistener
0 Comments

2 Answers

  • Accepted Answer

    You'll pass an object to fireEvent and then access it's properties in e, like this:

    app.js

    Titanium.App.fireEvent("some_event_name", { 
        res: this.responseText
    });
    

    webview.html

    <script type="text/javascript">  
    Titanium.App.addEventListener("some_event_name",function(e) {
         alert("hi"+e.res);
    });
    </script>
    

    Hope that helps

    — answered March 27th 2010 by Jacob Waller
    permalink
    2 Comments
    • ah great work, thx. Where do you find this info?

      — commented August 1st 2011 by Brian Burgess
    • I tried this on desktop, but fireEvent doesn't support sending an object. Ridiculous!

      — commented September 19th 2011 by Stefan Neumann
  • Hi

    assuming this.ResponseText contains the data you need

    Try this

        var webFormData = {};
        webFormData.Data = this.ResponseText;
    
        Titanium.App.fireEvent('webForm_DataIsAvailable', webFormData);
    

    and in your web form

    // Accept Data
    
    Ti.App.addEventListener('webForm_DataIsAvailable', webFormDataIsAvailableHandler);
    
    function webFormDataIsAvailableHandler(e) {
            var data = e.Data;
    }
    

    The reason i pass in a function pointer ie webFormDataIsAvailableHandler as opposed to the function(e) {} inline function is that its useful for cleaning up the handler at a later stage. using

    Ti.App.removeEventListener(&#39;webForm_DataIsAvailable&#39;, webFormDataIsAvailableHandler);

    I also you jQuery in my webform and have it fire an event to let the window know it is actually ready for the data first so something like this.

    
    $(function() {
                Ti.API.info('[WebForm] jQuery Ready');
    
                // Request Data
                Titanium.App.fireEvent('webForm_ReadyForData');
    });
    

    This is just to make sure the DOM is ready for the changes you want to make, but it may be overkill for your situation

    — answered March 27th 2010 by Mark Eggers
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.