【发布时间】:2023-03-22 06:21:01
【问题描述】:
我在 Laravel 中遇到问题,因为它显示错误。我正在使用 ajax 将请求从客户端发送到服务器并向后发送。这是我的 AJAX 代码,我怀疑函数 append() 不起作用。
$('#petition-form').on('submit', function(e) {
e.preventDefault();
var formdata = new FormData($(this)[0]);
formdata.append('content', tinymce.get('content').getContent());
$.ajax({
url: $(this).attr('action'),
data: formdata,
processData: false,
contentType: false,
cache: false,
method: 'POST'
}).done(function(response) {
window.location.href = response.slug;
}).fail(function(response) {
$(this).append(parseJSON(response));
// var getError = $.parseJSON(response);
});
}):
当我尝试console.log(response) 时,它会返回一个数组。
你能帮我解决这个问题吗?
【问题讨论】:
-
我遇到了同样的错误。但是在请求头中添加 Content-Type: application/json 解决了这个问题。