2014-09-22 48 views
0

嗨你好即时通讯新手机我想执行通知,所以我已经使用科尔多瓦插件添加 https://github.com/phonegap-build/PushPlugin.git来实现,现在即时获取注册ID和成功状态好,但我想存储REG_ID为我未来的目的 我已尽快使用AJAX POST方法,因为我们获得注册ID,但即时通讯无法发布 请帮我商店谷歌注册ID到我的数据库

<!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> 

回答

0

试试这个

$.ajax({ 
     url:'http://abcd.com/store.php, 
     data:'key='+e.regid, 
     success:function(data){ 
     alert(data); 
     } 
}); 

在你store.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';