0

当我点击一个href时,他们继续脚本代码但表单脚本不调用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'),

视图.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')
4

0 回答 0