Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ajax和django删除for循环中的项_Javascript_Jquery_Ajax_Django - Fatal编程技术网

Javascript 使用ajax和django删除for循环中的项

Javascript 使用ajax和django删除for循环中的项,javascript,jquery,ajax,django,Javascript,Jquery,Ajax,Django,正在尝试使用“单击并淡出”引导程序删除帖子/评论。我写了一些代码,但它不工作。我觉得我错过了这么简单的事情。任何指导或帮助都将不胜感激。 url.py 模板 {% for warns in warn.warnings.all %} <div class="warning-list col-md-4"> {# <a href="{% url 'delete' pk=warns.pk %}"> #}

正在尝试使用“单击并淡出”引导程序删除帖子/评论。我写了一些代码,但它不工作。我觉得我错过了这么简单的事情。任何指导或帮助都将不胜感激。 url.py

模板

{% for warns in warn.warnings.all %}
                <div class="warning-list col-md-4">
                {# <a href="{% url 'delete' pk=warns.pk %}"> #}
                <button type="button" class="close">&times;</button>
                {# </a> #}
                <div class="publish-date"><strong>Warned:</strong>  {{ warns.publish_date }}</div>
                <div class="posted-by"><strong>Warned By: </strong> {{ warns.author }}</div>
            <div class="warningtype"><strong>Warning Type: </strong>{{ warns.WarningType }}</div>
            <div class="description">
                <strong>Description:</strong> {{ warns.descript }}
            </div>
            {% endfor %}

main.js如下所示

$(".close").click(function () {
  var close=$(this).parent();
  if (confirm("Are you sure you want to delete this?")){
    $.ajax({
      type: "DELETE",
      url: $(this).data('url'),
      beforeSend: function(xhr) {
        xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
      },
      success: function() {
        close.fadeOut(1000);
      }
    });
  }
});
{% for warns in warn.warnings.all %}
                <div class="warning-list col-md-4">
                {# <a href="{% url 'delete' pk=warns.pk %}"> #}
                <button type="button" class="close">&times;</button>
                {# </a> #}
                <div class="publish-date"><strong>Warned:</strong>  {{ warns.publish_date }}</div>
                <div class="posted-by"><strong>Warned By: </strong> {{ warns.author }}</div>
            <div class="warningtype"><strong>Warning Type: </strong>{{ warns.WarningType }}</div>
            <div class="description">
                <strong>Description:</strong> {{ warns.descript }}
            </div>
            {% endfor %}
$(".close").click(function () {
  if (confirm("Are you sure you want to delete this?")){
$.ajax({
  type: "DELETE",
  url: "{% url 'delete' pk=warns.pk %}",
  beforeSend: function(xhr) {
    xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
  }
  success: function() {
    var close=$(this).parent();
    close.fadeOut(1000);
     });
    }
   })
  }
 });
$(".close").click(function () {
  var close=$(this).parent();
  if (confirm("Are you sure you want to delete this?")){
    $.ajax({
      type: "DELETE",
      url: $(this).data('url'),
      beforeSend: function(xhr) {
        xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
      },
      success: function() {
        close.fadeOut(1000);
      }
    });
  }
});