-2
如果有人能告诉我我需要做什么才能使此代码在IE和Firefox中都能正常工作,我将不胜感激。在Firefox中确认提示工作,但AJAX请求不会发生。 Firebug报告这个错误:jquery-1.11.1.js(9631行)。这是在该行发现了jQuery代码:jQuery AJAX适用于IE,但不适用于Firefox
xhr.send((options.hasContent && options.data) || null);
jQuery代码:
$(document).ready(function() {
$("#frmDelFiles").submit(function(event) {
var names = "";
var id_array = [];
var elements = document.getElementsByName('files2del');
for (var i = 0, l = elements.length; i < l; i++)
{
if (elements[i].checked)
{
//alert("ip_attachments record " + elements[i].id + " - " + elements[i].value + " is checked.");
var response = confirm("Do you consent to delete the " + elements[i].value + " file?\n\nClick OK if Yes, otherwise Cancel.");
if (response == true) {
id_array[id_array.length] = elements[i].id;
if (names == "") {
names = elements[i].value;
} else {
names += ", " + elements[i].value;
}
}
}
}
if (names == "") {
alert("Zero files have been selected for deletion.");
} else {
$.ajax({
type: "POST",
url: "del_ipa_rcd.php",
data: {id_array: id_array, names: names},
dataType: "html",
success: function(response){
$("#delete_result").html(response);
//alert(response);
}
});
}
});
});
PHP:
<form name='frmDelFiles' id='frmDelFiles' method='POST' class='frmFileUpload'>
<input type='submit' value='Delete Checked Files' name='delFiles' class='btnSubmit' />
</form>
...
...
while ($attach_row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo " <input type='checkbox' name='files2del' id='" . $attach_row['id'] . "' value='" . $attach_row['name'] . "'>\n";
echo " <a target='_blank' href='/php/dwnld_blob.php?column=content&tbl=ip_attachments&id=" . $attach_row['id'] . "'>" . $attach_row['name'] . "</a><br>\n";
}
您的' \ n”;'你可能想要使用一个模板系统而不是连接字符串,我也怀疑你使用'mysql_fetch_array'容易受到SQL注入的影响,你可能需要仔细检查你的XHR响应是还有一个XSS漏洞,你只是直接拿起HTML并从你的响应中呈现出来...... – 2014-09-29 18:25:16
那么.....什么是错误? – 2014-09-29 18:39:48
@Kevin,错误是AJAX del_ipa_rcd.php在Firefox中没有调用。Firebug在第9631行的jquery.js中报告错误。我可以在其他地方得到更具描述性的错误吗? – 2014-09-29 18:44:01