저는 이것을 위해 Javascript (JQuery가 아님)를 사용하고 있습니다. 확인란을 사용하여 선택한 MySQL 데이터베이스에서 레코드를 삭제하려고합니다. 삭제는 AJAX를 사용하여 발생하지 않습니다. 그러나, 나는 PHP AJAX 삭제 스크립트를 수동으로 동일한 매개 변수를 사용하여 삭제 작동합니다. 그러나 AJAX PHP를 수동으로 실행하면 모든 서버가 동일한 도메인에 있어도 Firefox 브라우저에서 COR을보고합니다. 여기 PHP AJAX MySQL 삭제가 작동하지 않습니다.
가있는 HTML, 자바 스크립트, AJAX PHP 삭제 스크립트 :가 중요한 경우 HTML은 iframe 내에입니다 :
<form name='frmDelFiles' method='POST' class='frmFileUpload' onClick='delChkdFiles("files2del")'>
<input type='submit' value='Delete Checked Files' name='delFiles' class='btnSubmit' />
</form>
자바 스크립트 :
function delChkdFiles(theCBgrp) {
var where_stmt = "";
var names = "";
var elements = document.getElementsByName(theCBgrp);
for (var i = 0, l = elements.length; i < l; i++)
{
if (elements[i].checked)
{
var response = confirm("Do you consent to delete the " + elements[i].value + " file?\n\nClick OK if Yes, otherwise Cancel.");
if (response == true) {
if (where_stmt == "") {
where_stmt = "id=" + elements[i].id;
names = elements[i].value;
} else {
where_stmt += " OR id=" + elements[i].id;
names += ", " + elements[i].value;
}
}
}
}
if (where_stmt == "") {
alert("Zero files have been selected for deletion.");
} else {
xmlhttp=getHTTPObject();
if (xmlhttp==null) {
alert ("Your browser does not support AJAX!");
return;
}
var url="/php/del_mysql_rcd.php";
url=url+"?table=ip_attachments";
url=url+"&where_stmt="+where_stmt;
url=url+"&names="+names;
url=url+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = handleShowResponse;
xmlhttp.send(null);
}
}
function handleShowResponse() {
if (xmlhttp.readyState==4) {
var ajaxStr = xmlhttp.responseText;
alert(ajaxStr);
}
}
del_mysql_rcd.php의 AJAX PHP :
<?php
$table = $_GET["table"];
$where_stmt = $_GET["where_stmt"];
$names = $_GET["names"];
require_once ('../php/mysql_connect.php'); // Connect to the db.
$query = "DELETE FROM $table WHERE $where_stmt";
$result = @mysql_query ($query) or die(mysql_error()); // Run the query.
if (mysql_affected_rows() > 0) {
echo "Successfully deleted $names\n";
} else {
echo "Failed to delete $names\n";
}
?>
금요일에 많은 의견이 있었다. 이제 그들은 모두 없어졌습니다. 왜? –
나는 그것들에 너무 많은 품질이 없다고 말할 것입니다 : p는 이것에 어떤 행운이 있습니까? –