我试图通过 AJAX/JSON 发布 POST,但服务器报告 HTTP 500 错误。
看法
url(r'^digajax$', 'digajax.views.main'),
url(r'^digajax_ajax$', 'digajax.views.ajax'),
模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$("#button").click(function() {
var input_string = $("#digInput").val();
$.ajax({
url : "/digajax_ajax",
type : "POST",
data : {
clientinput : input_string,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success : function(data) {
jQuery('#result').html(data).hide().fadeIn(1500);
},
error : function(xhr,errmsg,err) {
alert(xhr.status + ": " + xhr.responseText);
}
});
return false;
});
});
</script>
<form method="post" name="diginput form" action="/digajax_ajax">
{% csrf_token %}
<input name="digInput" id="digInput" type="text">
<input id="button" type="button" value="lookup"></input>
</form>
<p id="result">
</p>
</body>
</html>
任何想法,firebug 输出只显示 500 HTTP 错误。谢谢,