Open AngelTovarPaz opened 7 years ago
Find solutions.
var fcm_server_key = "AAAA-------";
$.ajax({
method: "POST",
dataType: 'json',
headers: {'Content-Type': 'application/json', 'Authorization': 'key=' + fcm_server_key},
url: "https://fcm.googleapis.com/fcm/send",
data: JSON.stringify(
{
"notification":{
"title":"Title", //Any value
"body": "Body", //Any value
"sound": "default", //If you want notification sound
"click_action": "FCM_PLUGIN_ACTIVITY", //Must be present for Android
"icon": "fcm_push_icon" //White icon Android resource
},
"data":{
"param1":"value1", //Any data to be retrieved in the notification callback
"param2": "Prueba"
},
"to":"/topics/all", //Topic or single device
"priority":"high", //If not set, notification won't be delivered on completely closed iOS app
"restricted_package_name":"" //Optional. Set for application filtering
}
)
}).success(function(data){
alert("Success: " + JSON.stringify(data));
}).error(function(data){
alert("Error: " + JSON.stringify(data));
});
Hello, I am using same code as above, however getting error message as HTML. If I delete "dataType: 'json'" part, I am getting success as HTML:( What am I missing?
In JQuery?
//POST: https://fcm.googleapis.com/fcm/send //HEADER: Content-Type: application/json //HEADER: Authorization: key=AIzaSy*** { "notification":{ "title":"Notification title", "body":"Notification body", "sound":"default", "click_action":"FCM_PLUGIN_ACTIVITY", "icon":"fcm_push_icon" }, "data":{ "param1":"value1", "param2":"value2" }, "to":"/topics/topicExample", "priority":"high", "restricted_package_name":"" }
Thanks