Rakesh Shetty Rakesh Shetty - 6 months ago 22
Android Question

window.localStorage.setItem not working on mobile phone

I am working on HTML5 mobile app using jQuery mobile.

This is my code:

$(document).on("click","#send_mobile_number",function(){

var mobile = $('#mobile_number').val();
var user_id = sessionStorage.getItem("user_id");


$('.ui-loader').show();

$.ajax({
url: BASE_URL+'users/send_sms_code.php',
type: 'POST',
datatype: 'json',
data: "user_id="+user_id+"&mobile="+mobile+"&type=1",
async:false,
success: function (response) {
var data = jQuery.parseJSON(response);
$('.ui-loader').hide();

if(data.status == 'Fail') {
$('.very_mob_no_message').html('Sorry some error occurred,try again.');
}else{
$('#close_mob_popup').trigger('click');

setTimeout(function()
{
$('.click_mobile_verify').trigger('click');
}, 500);

$('#send_mobile_verify_span').hide();
$('#after_mobile_send_span').show();

$('#moble_number_div').hide();
$('#user_code_div').show();

$('#user_code').val(data.sms_code);

//alert(window.localStorage.getItem('mobile'));

//sessionStorage.setItem("mobile",mobile);
window.localStorage.setItem("mobile",mobile); // IT IS NOT WORKING


$('.very_mobile_message').html('Enter code which is <br/> sent to your mobile number.');

}


},
error: function (jqXHR, textStatus, errorThrown) {

//alert(jqXHR.status);
}
});

});


I want to store mobile number in session using
window.localStorage.setItem("mobile",mobile);
. It is working when I run on my browser but when I runt on mobile phone as APP it stop working. Why this happening. I am checking android phone.

Answer

So finally found the solution, I need to set webSettings.setDomStorageEnabled(true); on android code and after this localstorage is working perfectlly.