javascript - jQuery ajax 不发送响应
问题描述
我正在将数据发送到特定的 URL,然后我尝试使用 ajax 获取它,它只是打印一个错误
<script type="text/javascript" src="{{ url_for('static', filename='jquery.js') }}"></script>
<script>
$(document).ready(function()
{
$.ajax({
method: "POST",
url: "/computers/{{id}}",
dataType: "json",
async: true,
succsess: function(data){
var json = $.parseJSON(data); // create an object with the key of the array
alert(json.html);
console.log(data)
},
error: function(error){
console.log("Error:");
console.log(error);
}
});
});
</script>
^ 这就是我收到请求的方式(id 为 2)
解决方案
问题是我没有发送任何数据,但我也在输入,dataType: "json"
所以出错了。
$.ajax({
method: "POST",
url: "/computers/{{id}}",
async: true,
succsess: function(data){
var json = $.parseJSON(data); // create an object with the key of the array
alert(json.html);
console.log(data)
},
error: function(error){
console.log("Error:");
console.log(error);
}
});
所以这是正确的代码,因为我没有发送任何数据。
推荐阅读
- java - 任务 ':app:compileProductionReleaseJavaWithJavac' 执行失败。> javax/xml/bind/JAXBException
- javascript - Youtube:this.f.isExternalMethodAvailable 不是函数
- flutter - 如何正确使用具有多个滚动位置的 ScrollController?
- r - 使用 R 包 RJulia
- c# - 在逻辑上将大字符串拆分为合适的子字符串
- html - 如果被另一个元素覆盖,则响应 CSS 悬停选择器
- r - 使用分组对长格式数据框进行 t.test 测试很热门吗?
- python - 从 R 到 Python 的循环
- scrapy - 爬虫、cookies、会话、速率限制
- java - 我如何在 android 中实现 ActivityOptions.setLaunchDisplayId(1) marshmallow?