Javascript 更新烧瓶而不刷新
这是我使用ajax连接flask的java脚本,但它显示了404错误。我不明白我哪里出错了Javascript 更新烧瓶而不刷新,javascript,python,jquery,flask,python-requests,Javascript,Python,Jquery,Flask,Python Requests,这是我使用ajax连接flask的java脚本,但它显示了404错误。我不明白我哪里出错了 <script> function getBotResponse() { var rawText = $("#textInput").val(); var userHtml = '<p class="userText"><span>' + rawText + '</span></p>'; $("#t
<script>
function getBotResponse() {
var rawText = $("#textInput").val();
var userHtml = '<p class="userText"><span>' + rawText + '</span></p>';
$("#textInput").val("");
$("#chatbox").append(userHtml);
document.getElementById('userInput').scrollIntoView({block: 'start', behavior: 'smooth'});
$.ajax({
type: 'POST',
url: '/predicton',
dataType: 'json',
contentType: 'application/json; charset=utf-8'
}).done(function(data) {
var botHtml = '<p class="botText"><span>' + data + '</span></p>';
$("#chatbox").append(botHtml);
document.getElementById('userInput').scrollIntoView({block: 'start', behavior: 'smooth'});
});
}
$("#textInput").keypress(function(e) {
if(e.which == 13) {
getBotResponse();
}
});
$("#buttonInput").click(function() {
getBotResponse();
})
</script>
您的脚本中存在键入错误:
url: '/predicton'
一定是
url: '/prediction'
(在JS实现中)您收到的错误或异常是什么实际上我是在迎接404错误,但当我使用时,我得到了正确的结果,但它刷新了页面,我不想纠正并尝试运行该页面,它显示了TypeError:“NoneType”对象没有属性“getitem”
url: '/prediction'