Вызов функции просмотра и отправка FCM без Refre sh Page Using AJAX In Django - PullRequest
0 голосов
/ 22 апреля 2020

Когда я нажимаю a href они go на Сценарий код, но форма Сценарий не вызывает функцию views.py!

Код ссылки ::

<a class="likebutton" href="#">
    <span id="unlock">
        <i class="fas fa-lock"></i>&nbsp;Send Message
    </span>
</a>

Код сценария ::

<script type="text/javascript">
  $('.likebutton').click(function(){ 
    $.ajax( 
    { 
        type:"GET", 
        url: "sendnotification",  
        success: function(){  
          alert('Done')
        } }) });
</script>

urls.py ::

url(r"^sendnotification",views.sendnotification,name='sendnotification'),

views.py ::

@csrf_exempt
def sendnotification(request):
  if request.method == 'GET':
      push_service = FCMNotification(api_key="*********")
      registration_id = "****************"
      data_message = {
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"}
      result = push_service.single_device_data_message(registration_id=registration_id, data_message=data_message)
return HttpResponse('success')
...