我有一个使用 jquery 的简单 Ajax 调用:
jQuery(".deletebutton").on("click", function() {
if (confirm("Are you sure you want to delete?"))
{
jQuery.ajax({
url: 'index.php?option=com_recordings&task=deletevideos&format=raw',
type: "POST",
success: function(data){
console.log("anything?"); //never get here with FF and Chrome
if (data == 'blah')
{
alert("success"); //only with IE
}
}
});
}
});
网址很奇怪,因为我正在使用 Joomla 组件开发。它本质上指向一个具有echo "blah";
. html 只是一个带有 class 的按钮deletebutton
。
在 IE 上,此代码工作正常并触发警报。在 FF 和 Chrome 上它不起作用。检查jqXHR.status
显示它返回 0。我在 Firebug 中看不到任何指向我这里问题的东西。知道发生了什么吗?
编辑:我注意到它与我的 html 按钮有关。当前按钮在表单内:
<form name="myform" action="">
<table id="webcam-table" class="pretty">
<thead>
<tr>
<th>Camera Name</th>
<th>Date Created</th>
<th>Video Size</th>
<th>Video Length</th>
<th>
<input type="checkbox" name="checkboxselectall" title="Select All" />
<button class="deletebutton" title="Delete the selected videos" >Delete</button>
... //a table with checkboxes (for the form) and other stuff
</form>
但是如果我在这个表单之外创建一个简单的按钮,我的 ajax 调用会按预期工作。这里发生了什么?