使用AJAX的GCM / FCM推送通知

时间:2020-02-19 01:17:14

标签: ajax notifications google-cloud-messaging push

当我使用邮递员点击发送推送通知的api时,我能够获得推送通知,但是当我对他的API使用AJAX请求时,则没有任何通知。 AJAX代码如下:

$.ajax({
                type: 'POST',
                url: "https://fcm.googleapis.com/fcm/send",
                headers: {
                    Authorization: 'key=' + 'MY-KEY',

                },
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify({
                    "registration_ids": ["ewwPfjNyaWE:APA91bFI9cZBPjX9yXO_Du0O6Dm2tmmSZLdfu3JtBJIdzg_qrOr32W-YGRxsZbzxIt3V7Y5vcj7Ua5NWdzxrMExgBFJYX_WBQZq0buqDcQ6KqCuLx59hlo6NSRS9DilHhuP0KogRqHyf"],
                    "data": {
                        'title' : 'Testing Notification',
                        'body' :'Testing Notification from localhost',
                        'icon' :'img/icon.png',
                        'image' :'img/d.png',
                    }
                }),
                success: function(response) {
                    console.log(response);
                },
                error: function(xhr, status, error) {
                    console.log(xhr.error);
                }
            });

0 个答案:

没有答案