Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript runs fine in browser but not working in phonegap iOS
    primarykey
    data
    text
    <p>I am using Phonegap 2.9.0 and Xcode 4.6.3. I am making a registration form using jquery mobile 1.3.2 and html 5.</p> <p>I am facing a strange problem, if I run the html file in a browser it is behaving perfectly as it should but when running on the iPhone simulator none of the validating scripts work. I've tried safari web console to debug the problem, but couldn't figure out the any.</p> <p><strong>EDIT</strong></p> <p>cordova has DOM issues when trying to navigate in different html files. So I've modified my code. Instead of navigating into a entire different html file, I am trying to change the inner html content of a div.</p> <p>Here is what I've tried:</p> <p><strong>index.html</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="format-detection" content="telephone=no" /&gt; &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /&gt; &lt;link rel="stylesheet" href="js/jquery.mobile-1.3.2.css" /&gt; &lt;link rel="stylesheet" href="js/jquery.mobile.structure-1.3.2.css" /&gt; &lt;link rel="stylesheet" href="js/jquery.mobile.theme-1.3.2.css" /&gt; &lt;link rel="stylesheet" href="js/jquery.ui.datepicker.mobile.css" /&gt; &lt;title&gt;Bookstore&lt;/title&gt; &lt;/head&gt; &lt;body onload="onBodyLoad()"&gt; &lt;div id="main_content"&gt; &lt;/div&gt; &lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt; &lt;script&gt; //reset type=date inputs to text $( document ).bind( "mobileinit", function(){ $.mobile.page.prototype.options.degradeInputs.date = true; }); &lt;/script&gt; &lt;script type="text/javascript" src="js/jquery-1.7.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.mobile-1.3.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jQuery.ui.datepicker.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.ui.datepicker.mobile.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt; &lt;script&gt; function onBodyLoad() { document.addEventListener("deviceready",onDeviceReady,false); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>index.js</strong></p> <pre><code>var latitude; var longitude; $(document).bind('deviceready', function(){ navigator.geolocation.getCurrentPosition(onSuccess, onError); $("#main_content").load('user_register.html'); registration(); }); function alertDismissed() { // do something } function is_email(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function onSuccess(position) { latitude = position.coords.latitude; longitude = position.coords.longitude; } function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } function registration() { $("#register").submit(function() { $('.error').hide(); var user_name = $("input#user_name").val(); if (user_name == "") { navigator.notification.alert( 'Please fill up user name.', // message alertDismissed, // callback 'User Name', // title 'Done' // buttonName ); // alert("Please fill up user name."); return false; } if (!is_email(user_name)) { navigator.notification.alert( 'Not a valid email.', // message alertDismissed, // callback 'User Name', // title 'Done' // buttonName ); // alert("Not a valid email."); return false; } var password = $("input#password").val(); if (password == "") { navigator.notification.alert( 'Please fill up password.', // message alertDismissed, // callback 'Password', // title 'Done' // buttonName ); // alert("Please fill up password."); return false; } if (password.length &lt; 6) { navigator.notification.alert( 'Password too short.', // message alertDismissed, // callback 'Password', // title 'Done' // buttonName ); // alert("Password too short."); return false; } var confirm_password = $("input#confirm_password").val(); if (confirm_password == "") { navigator.notification.alert( 'Please fill up confirm password.', // message alertDismissed, // callback 'Confirm Password', // title 'Done' // buttonName ); // alert("Please fill up confirm password."); return false; } if (confirm_password != password) { navigator.notification.alert( 'Password and confirm password field does not match.', // message alertDismissed, // callback 'Confirm Password', // title 'Done' // buttonName ); // alert("Password and confirm password field does not match."); return false; } var full_name = $("input#full_name").val(); if (full_name == "") { navigator.notification.alert( 'Please fill up your full name field.', // message alertDismissed, // callback 'Confirm Password', // title 'Done' // buttonName ); // alert("Please fill up your full name field"); return false; } var date_of_birth = $("input#date_of_birth").val(); var sex = $("input#sex").val(); var dataString = 'user_name='+ user_name + '&amp;password=' + password + '&amp;name=' + full_name + '&amp;sex=' + sex + '&amp;date_of_birth=' + date_of_birth; var obj; $.ajax({ type: "POST", url: "test.php", data: dataString, success: function(data,textStatus,XMLHttpRequest) { obj = jQuery.parseJSON(data); navigator.notification.alert( obj.message, // message alertDismissed, // callback 'Confirm Password', // title 'Done' // buttonName ); // alert(obj.message); }, error: function(XMLHttpRequest, textStatus, errorThrown) { var msg = 'There was an ' + errorThrown + ' error due to a ' + textStatus + ' condition.'+ 'XMLHttpRequest: ' + XMLHttpRequest[0] + ' Error Thrown: ' + errorThrown; navigator.notification.alert( msg, // message alertDismissed, // callback 'Confirm Password', // title 'Done' // buttonName ); }, complete: function(XMLHttpRequest, status) { if (obj.status == 0) { $('form')[0].reset(); $("#main_content").load('user_login.html'); } } }); return false; }); } </code></pre> <p><strong>user_register.html</strong></p> <pre><code>&lt;div data-role="page" id="register"&gt; &lt;div data-theme="a" data-role="header" data-position="fixed"&gt; &lt;a data-role="button" data-transition="slidedown" href="index.html" class="ui-btn-left"&gt; Cancel &lt;/a&gt; &lt;h3 id="register"&gt; Register &lt;/h3&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;form id="register"&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="user_name"&gt; User Name &lt;/label&gt; &lt;input name="user_name" id="user_name" placeholder="user@email.com" value="" type="email"&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="password"&gt; Password &lt;/label&gt; &lt;input name="password" id="password" placeholder="password" value="" type="password"&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="confirm_password"&gt; Confirm Password &lt;/label&gt; &lt;input name="confirm_password" id="confirm_password" placeholder="password" value="" type="password"&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="full_name"&gt; Full Name &lt;/label&gt; &lt;input name="full_name" id="full_name" placeholder="First Middle Last" value="" type="text"&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="sex"&gt; Sex: &lt;/label&gt; &lt;select id="sex" name="sex"&gt; &lt;option value="0"&gt; Male &lt;/option&gt; &lt;option value="1"&gt; Female &lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="date"&gt;Date of Birth:&lt;/label&gt; &lt;input type="date" name="date_of_birth" id="date_of_birth" value="" /&gt; &lt;/div&gt; &lt;input id="submit" type="submit" value="Submit"&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>Now the app runs and just a white screen appears. It doesn't load the user_register.html as expected!</strong></p> <p>Any help would be cordially appreciated :)</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.
    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