OneSignal在Web通知上发送js变量

问题描述 投票:0回答:1

有谁知道如何在网络通知内容上发送js变量?

我正在尝试下面的代码但是没有工作,我得到了空的内容。

我将我的PHP变量添加到JS变量noticeText,内容就在那里,但是在通知内容中没有显示任何内容。

<script type="text/javascript">
                                var noticeText = "<?php echo $noticeTitle; ?>";
				var settings = {
				  "async": true,
				  "crossDomain": true,
				  "url": "https://onesignal.com/api/v1/notifications",
				  "method": "POST",
				  "headers": {
				    "cookie": "__cfduid=d7e029aceb39ed3bc3b64849b5358bf3a1544538404",
				    "authorization": "Basic MzVmZGQ5ZWQtNGI5OC00YTU5LWFhOGUtMTZhZWVmMzg3MGIx",
				    "content-type": "application/json"
				  },
				  "processData": false,
				  "data": 
'{"app_id": "dc44e367-f59b-41fd-a7c9-1b25cfd8cb66","included_segments": ["All"],"headings": {"en": "Hey {{ first_name }} {{ last_name }}", "tr": "Turkish {{ first_name }} {{ last_name }}"},"contents": {"en": "{{ noticeText }}", "tr": "Turkish Content"}}'
				}
				
				$.ajax(settings).done(function (response) {
				  console.log(response); 
				});
			</script>
javascript php push-notification notifications onesignal
1个回答
0
投票

直接的php回声起作用最终的诀窍就是把它放在“”一个挥之不去的作品中

© www.soinside.com 2019 - 2024. All rights reserved.