- This topic has 0 replies, 1 voice, and was last updated 12 years, 6 months ago by support-michael.
-
AuthorPosts
-
support-michaelKeymasterLOAD PHP GENERATED DATA FILE ACROSS DOMAINS
Frequently developers run into frustrating cross-domain security restrictions when their webapp attempts to access resources and services from domains other than the domain from which their webapp originates. An example of this is when your webapp is loaded from http://myserver.com/index.html and attempts to submit a form or make an ajax call to http://anotherserver.com. This example demonstrates one approach to retrieving a data file generated by PHP on non-origination server.
For background on the problem see the following resources:
http://en.wikipedia.org/wiki/Same_origin_policy
http://enable-cors.org/Getting Started
1) Create PHP file and set the response header to enable cross domain requestsSee attachment loaddata1-php.png
You can access a version of this doc at http://genuitec.com/mobile/mobione/dev/web/test-data/data.php2. Design UI
Using the Visual Designer I laid out the following user interface. There are 2 use-cases supported:
– Load Data
– Clear DataSee these resources for tips on working with widgets and JavaScript snippets:
Working with Generated Source Files
Interacting with Widgets: JavaScript Snippets
Load Data Use-case
The screen is configured as a Form with the Form Action URL property set to the URL provided above. In the load_custom.js file I modify the phoneui.postSubmitForm_m1_loaddata() function to display the text I received in the textarea widget or to display an error message if the form submission fails for some reason. This function was generated by MobiOne and is called upon completion of my form submission.See attachment loaddata1-dc.png
See attachment loaddata1-tc.png
Clear Data Use-case
I set the Click Event property to a Run JavaScript action. I included a snippet that looks up the textarea widget and replaces its content with an empty string.Testing
1. Enable Local Web Server
Before doing this ensure that the local webserver is enabled, see Window menu>Settings>Local Web Server.2. Launch webapp in Test Center
From the Design Center use the Run in Test Center button to generate the HTML code for the UI and to launch the webapp in the Test Center. Also[b]3. Disable Local Web Server proxying support
In Test Center click the iPhone status bar to reveal the screen’s URL. Scroll to the end and starting at and including the “?” delete the remaining portion of the URL.
See attachment loaddata1-urledit.pngProject Code
See attachment cors-testing.zipAttachments:
You must be logged in to view attached files. -
AuthorPosts