I am trying to register GCM ids of various devices on my webserver so that I can send push notifications. I have used the following code to get the GCM id of a device.
<script type="text/javascript">
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady(){
console.log("Device Ready")
var push = PushNotification.init({ "android": {"senderID":"989946143452"},
"ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );
push.on('registration', function(data) {
console.log(data.registrationId);
$("#gcm_id").html(data.registrationId);
});
push.on('notification', function(data) {
console.log(data.message);
alert(data.title+" Message: " +data.message);
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
});
push.on('error', function(e) {
console.log(e.message);
});
}
</script>
Then I am using the following this form field to parse the gcm id from the javascript to the html form field,
<input type="hidden" name="gcm_id" id="gcm_id" required/>
The form field seems not to be getting the gcm_id value. Any workarounds on this?
Of couser I am using ajax to send the data to the php script that will store the gcm_id on my MySQL table.