大神求助:form提交后 ajax没有反应
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script><script>
$(document).ready(function(){
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
$('#formadd').submit(function(){
var img_url = $("#img_url").val();
$.ajax({
type:"POST",
data: {img_url:img_url},
url: "{% url 'save' %}",
cache: false,
dataType: "html",
success: function(result, statues, xml){
alert(result);
},
error: function(){
alert("false");
}
});
return false;
});
});
</script>
------------------------------------------------------------------
{% for img in contacts %}
<a href="{{ img.pic_url }}" class="pic-list">{{ img.title }}><br/>
<img src= "{{ img.pic_url }}" ><br/>
<form method="post" id="formadd">
{% csrf_token %}
<input type="hidden" id="img_url" value="{{ img.pic_url }}"/>
<button type = "submit" id="submit">保存</button>
</form>