将html日期传递到django模型时,jQueryAjax调用出现HTTP 500错误
我正在使用html格式的日期选择器表单(见下图),我想将这些数据传递到我的django模型中 我已经成功地从一个选项类向django模型传递了表单数据,代码类似。但是,当传递所选日期时,我会收到一篇XHR帖子http://127.0.0.1:1234/ 错误 我对AJAX非常陌生,但我听说我应该远离创建XHR对象。我是否在这里创建了一个,如何避免创建它们?谢谢将html日期传递到django模型时,jQueryAjax调用出现HTTP 500错误,html,jquery,ajax,Html,Jquery,Ajax,我正在使用html格式的日期选择器表单(见下图),我想将这些数据传递到我的django模型中 我已经成功地从一个选项类向django模型传递了表单数据,代码类似。但是,当传递所选日期时,我会收到一篇XHR帖子http://127.0.0.1:1234/ 错误 我对AJAX非常陌生,但我听说我应该远离创建XHR对象。我是否在这里创建了一个,如何避免创建它们?谢谢 <div class="container"> <div clas
<div class="container">
<div class="row">
<div class="col-9">
<div class="date">
<br>
<h3>Select to view distance and orders by timeframe</h3>
<form method="POST">
<label for="start">Start date:</label>
<input type="date" id="start" name="trip-start" value="2018-12-01" min="2018-12-01"
max="2019-06-30">
<label for="end">End date:</label>
<input type="date" id="end" name="trip-end" value="2018-12-01" min="2018-12-01"
max="2019-07-01">
<br>
<br>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$("#start").change(function () { // calling select id
const start_date = $(this).val(); // get the selected subject ID from the HTML dropdown list
$.ajax({ // initialize an AJAX request
type: "POST",
url: '',
data: {
'start_date': start_date, // add the order id to the POST parameters
'csrfmiddlewaretoken': "{{csrf_token}}",
},
success: function (data) { // `data` is from `homepage` view function
console.log("this block of code isn't useless!!")
console.log(data.start_date)
}
});
});
$("#end").change(function () { // calling select id
const end_date = $(this).val(); // get the selected subject ID from the HTML dropdown list
$.ajax({ // initialize an AJAX request
type: "POST",
url: '',
data: {
'end_date': end_date, // add the order id to the POST parameters
'csrfmiddlewaretoken': "{{csrf_token}}",
},
success: function (data) { // `data` is from `homepage` view function
console.log("this block of code isn't useless!!")
console.log(data.end_date)
}
});
});
</script>
</div>
您遇到服务器错误,即:您的服务器代码有问题。我尝试清除缓存并删除cookies,但没有成功