javascript - 当帖子正文内容为 JSON 但响应为 HTML 时,发出 jquery ajax post 请求

标签 javascript jquery

我正在发出以下 jquery ajax post 请求:

$.ajax({
                url: '/foo',
                type: 'post',
                dataType: 'html',
                data: JSON.stringify(barsJSON),
                success: function (responseHTML) {
                    $('#content').html(responseHTML);
                }

                });

服务器期望帖子正文内容为 JSON 类型,但服务器发送的响应是 HTML。以上正确吗?

最佳答案

添加内容类型

示例内容类型:'application/json'

关于javascript - 当帖子正文内容为 JSON 但响应为 HTML 时,发出 jquery ajax post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50410051/

相关文章:

javascript - 在这种情况下,什么时候 Backbone JS 模型 View 会被垃圾回收?

javascript - 通过单击网格 Devextreme 上的按钮打开 Treeview

javascript - jquery点击按钮问题

javascript - Coffeescript错误编译

php - 在浏览器级别将数据从一个网站发送到另一个网站

javascript - meteor - 在选择更改时更新 var

jquery - Jquery-steps : undefined is not a function on . validate() 函数上的表单验证

javascript - 如何查看 "real time"中输入的内容

java - 如何在 Spring MVC Controller 中接受二维数组?

javascript - 无法通过本地服务器运行Vega-Lite可视化示例