Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery .get() not working in a click event function callback
    primarykey
    data
    text
    <p>I have been fighting this peculiar problem for quite a few days, to no avail. Since this is freelance work my neck is on the line and I need your help.</p> <p>Firstly I am creating an app using phonegap and jQuery 1.9.1. The app goes online and gets an itinerary in csv format and keeps it in the app. The jQuery get() function is used for this.</p> <p>This is where it gets weird. The get function works fine when fired on phonegap's DeviceReady event, like is shown below:</p> <pre><code>onDeviceReady: function() { $( document ).bind( "mobileinit", function() { $.mobile.allowCrossDomainPages = true; }); $.get('http://dl.dropboxusercontent.com/u/53792213/App/DavidColson.csv', function(data) { alert('Success'); }, "text") .fail(function(jqXHR, textStatus, errorThrown) { alert("An AJAX error occured: " + textStatus + "\nError: " + errorThrown); }); }); }, </code></pre> <p>As you can see cross domain pages are allowed and so everything runs smoothly and I get the 'Success' alert.</p> <p>However if I want this to be called on an event, say when a user clicks on a button, It will not work. Look at this below:</p> <pre><code>onDeviceReady: function() { $( document ).bind( "mobileinit", function() { $.mobile.allowCrossDomainPages = true; }); $("#itineraryAddButton").bind("click", function(event) { alert("Event fired"); $.get('http://dl.dropboxusercontent.com/u/53792213/App/DavidColson.csv', function(data) { alert('Success'); }, "text") .fail(function(jqXHR, textStatus, errorThrown) { alert("An AJAX error occured: " + textStatus + "\nError: " + errorThrown); }); }); }, </code></pre> <p>The 'Event fired' alert fires, and then the fail function fires and tells me an ajax error has occured, however the <code>errorThrown</code> string is empty, not giving me any clues.</p> <p>To make it even harder to fix, this only happens when on a physical android device, it works perfectly in a browser and on a virtual android device, making it neraly impossible to debug.</p> <p>If you would like more information on software versions please tell me, and any other information you would like to help me solve this problem.</p> <p>David</p> <p>EDIT:</p> <p><a href="https://dl.dropboxusercontent.com/u/53792213/itineraryapp.apk" rel="nofollow">https://dl.dropboxusercontent.com/u/53792213/itineraryapp.apk</a> Here is a download link to an unsigned apk to try out. When the app opens click "Add Itinerary" and then a box will appear, what you type in is irrelevant, click "Go get it" to trigger the get() function and watch the alerts.</p> <p>'Hello' if the event was fired 'Success' if get worked 'An ajax error occured' if it didn't</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload