Search code examples
androidjqueryajaxcordova

Error On button click event in Android Phonegap application


I have a button in my phonegap HTML page to which i have added a button click event and ajax call to webservice URL.At present i am not calling any webservice URL but the main issue that i have is that my button click event is not getting fired .on logcat it is giving following error..

stale touch event action_down received from webcore ignoring

Here is my button HTML code..

<div style="display: table; margin: 0 auto; background-color: green;">
<button id="call" class="button">Call</button>
</div>

and here is my js file code for button click event ..

//Add event listener to run when the device is ready
document.addEventListener("deviceready", onDeviceReady, false);

//Device is ready
function onDeviceReady() {
$(document).ready(function(){
$('#call').bind('click',function(evt){
    senddata();
});
});
} 

function senddata(){  
e.preventDefault();             
var empname=$("#name").text();
alert(empname); 

var contactno=$("#contact").text();
alert(contactno); 

//Webservice URL
var URL="index.html";

$.ajax({
    url: URL,
    data: "",
    type: 'POST',
    success: function (resp) {
        alert(resp);
    },
    error: function(e) {
        alert('Error: '+e);
    }  
});
}

Please help me to resolve this issue..Thanks..


Solution

  • Instead of bind() just use the following:

    $(document).on('click', '#Login_button', function() {
    
    //Call your method to call webservice.
    
    senddata();
    
    }
    

    or other way to add click event to button is following:

    <button id="call" onclick="senddata();">Call</button>