【发布时间】:2017-02-24 11:29:53
【问题描述】:
我有这个功能:
function deleteDocument(e, document_id, property_id) {
e.preventDefault();
$('#editDocumentLoader').css('display', 'flex');
$.ajax({
type: "POST",
dataType: "json",
url: window.location.protocol + "/profile/property/document/delete/" + document_id,
data: {
'document_id': document_id,
'property_id': property_id,
'_token': CSRF_TOKEN
},
cache: false
}).done(function(response) {
alert(response);
if (response != "") {
try {
$('#document_table').html(response.data);
$('#editDocumentLoader').hide();
} catch (e) {
console.log(e)
}
} else {
console.log("no response");
}
}).fail(function(response) {
console.log(response);
if (response.status == 422) {
var errors = response.responseJSON;
}
});
}
在我看来,form 里面有这个:
<button onclick="deleteDocument(event,{{$document->id}},{{$property->id}})"><i class="fa fa-times"></i></button>
由于某种原因,它提交了我的表单,然后我的 ajax 调用不起作用。有什么建议吗?
【问题讨论】:
-
“ajax 调用不起作用”是什么意思?它会抛出错误吗?请求是否返回错误响应?反应错了吗?
-
它返回一个错误响应
-
那么错误说明了什么?
-
那你为什么说不返回错误呢?
-
url: window.location.protocol + "/profile/property/document/delete/" + document_id- 这将为您提供http:/profile/property/document/delete/123形式的结果 url - 您真的认为尝试请求 that 有意义吗?