4
我試圖使用jQuery提交表單與AJAX:jQuery的AJAX jqXHR.status始終爲0
<form name="myform" action="">
<table id="webcam-table">
<thead>
<tr>
<th>Name</th>
<th>...</th>
<th><input type="checkbox" name="checkboxselectall" title="Select All" />
<button type="submit" class="deletebutton" name="delete_video" title="Delete the selected videos">Delete</button></th>
</tr>
</thead>
<tbody>
<tr >
<td>some data</td>
...
<td><input type="checkbox" value="<?php echo $this->result_videos[$i]["video_name"]; ?>" title="Mark this video for deletion"/></td>
</tr>
</tbody>
</table>
</form>
如果有人選擇複選框,並點擊提交按鈕,我有這樣的代碼:
jQuery(".deletebutton").on("click", function() {
var testchecked = jQuery(':checkbox:checked').length;
if (testchecked == 0) {
alert('Please select at least one video');
e.preventDefault();
}
else
{
if (confirm("Are you sure you want to delete the selected videos?"))
{
var checked = jQuery('input:checkbox:checked').map(function() {
return this.value;
}).get();
var $this = jQuery(this);
jQuery.ajax({
type: 'POST',
url: 'index.php?option=com_recordings&task=deletevideos&format=raw',
data: {checkedarray:checked},
success: function(data){
alert(data);
}
});
}
}
});
奇怪的是,這段代碼在IE中工作正常(如何進行更改),但不在Chrome或FF中。如果我檢查錯誤:
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 0) {
alert("Not connected. Verify Network.");
}
它似乎總是會引發此警報。那爲什麼它總是0?這真的很奇怪。經過一番玩弄如果我改變的形式是在那工作表:
<table id="webcam-table">
<thead>
<tr>
<th>Name</th>
<th>...</th>
<th><input type="checkbox" name="checkboxselectall" title="Select All" />
<button type="submit" class="deletebutton" name="delete_video" title="Delete the selected videos">Delete</button></th>
</tr>
</thead>
<tbody>
<form name="myform" action="">
... //the rest is the same
這將隨後在FF和Chrome的工作,但現在IE無法正確顯示錶。所以這不是一個解決方案(反正它不是W3C有效的代碼)。那麼......有什麼想法?任何我可以嘗試調試這個?
非常感謝! – Tom