将谷歌注册id存储到我的数据库中
store Google register id to my database
你好,我是phonegap的新手,我想实现通知,所以我使用了cordova插件添加https://github.com/phonegap-build/PushPlugin.git为了实现,现在我获得了注册id和成功状态OK,但我想存储该REG_id以备将来使用我在获得注册id后就使用了ajax发布方法,但我无法发布请帮我
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript">
var pushNotification;
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
pushNotification = window.plugins.pushNotification;
if ( device.platform == 'android' || device.platform == 'Android' ){
pushNotification.register(
successHandler,
errorHandler, {
"senderID":"1234560",
"ecb":"onNotificationGCM"
});
}
}
// Android
function onNotificationGCM(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$.ajax({
url: "http://abcd.com/store.php",
context: document.body,
cache : false,
data: {
username : e.regid,
},
success: function ( data ) {
alert("regID success");
}
});
$("#app-status-ul").append('<li>REGISTERED ID is : -> REGID:' + e.regid + "</li>");
console.log("regID = " + e.regid);
}
break;
case 'message':
if ( e.foreground )
{
$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');
var my_media = new Media("/android_asset/www/"+e.soundname);
my_media.play();
}
else
{
if ( e.coldstart )
{
$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
}
else
{
$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');
break;
case 'error':
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;
default:
$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received
and we do not know what it is</li>');
break;
}
}
function successHandler (result) {
$("#app-status-ul").append('<li>success ID:'+ result +'</li>');
}
function errorHandler (error) {
$("#app-status-ul").append('<li>error:'+ error +'</li>');
}
</script>
<title>com.PhoneGap.c2dm</title>
</head>
<body onload="onLoad()">
<div id="home">
<div id="app-status-div">
<ul id="app-status-ul">
<li>Cordova PushNotification Plugin Demo</li>
</ul>
</div>
</div>
试试这个
$.ajax({
url:'http://abcd.com/store.php,
data:'key='+e.regid,
success:function(data){
alert(data);
}
});
在您的店铺中.php
//read the regid from device
$key=$_GET['key'];
//perform your query
$ins_qry=mysql_query();
if($insq_qry)
echo 'Registration success';
else
echo 'Error occured';
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我应该把维基百科的数据保存到我的数据库中吗
- 如何在谷歌地图上显示我的数据库地址,不带lat和long
- 谷歌地图(它没有将结果显示到我的输入窗格中以保存到我的数据库中)
- 无法让我的幻灯片通过我的数据库工作
- 节点发布 将新记录插入我的数据库不会返回新条目的数据
- 点击后没有错误检测,但无法发布到我的数据库
- 将图像上传到服务器(picasa/dropbox/etc)并检索url以将其保存在我的数据库中
- 如何将所有列存储到我的数据库中?通过Javascript
- 尝试通过AJAX发送数字,然后将它们添加到我的数据库中
- 我的数据库通过Phonegap存储在Android中的/data/data/package-name/app_datab
- 将谷歌注册id存储到我的数据库中
- 为什么我的数据库对象的集合为空
- 事件(表内容可编辑)并发送到PHP文件以更新我的数据库
- 我的帖子没有;t插入我的数据库
- 如何连接到我的数据库与javascript和更改用户的用户名
- 我怎么知道什么是我的数据库在我的服务器上的主机名
- 外部脚本已被注入到我的数据库
- 如何重写jQuery日历的删除,以便我也可以删除我的数据库数据
- Post数据通过php到我的数据库在AngularjS