我的代码在XAMPP服务器中运行正常,但是当我在实时服务器上将其上传时,它出现错误-“ DataTables警告:表格ID = user_data-Ajax错误。有关此错误的更多信息,请参见http://datatables.net/tn/7”
On xampp server screenshot working ok
On live server error screenshot
这是我的验证码
index.php
<html>
<head>
<title>Delete Mysql Data using jQuery Dialogify with PHP Ajax</title>
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="css/dataTables.bootstrap.min.css" />
<script type="text/javascript" src="js/jquery.min2.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/dialogify.min.js"></script>
</head>
<body>
<div class="container">
<br />
<h3 align="center">Delete Mysql Data using jQuery Dialogify with PHP Ajax</h3>
<br />
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
<h3 class="panel-title">Products</h3>
</div>
<div class="col-md-6" align="right">
<button type="button" name="add_data" id="add_data" class="btn btn-success btn-xs">Add</button>
</div>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<span id="form_response"></span>
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<td>Clone</td>
<td>View</td>
<td>Edit</td>
<td>Delete</td>
<td>ID</td>
<td>Product ID</td>
<td>Refrence Code</td>
<td>Category</td>
<td>Sub Category</td>
<td>Product Name</td>
<td>Product Description</td>
<td>Style</td>
<td>Fabric</td>
<td>Material</td>
<td>Type</td>
<td>Color Features</td>
<td>Size Features</td>
<td>Color Attributes</td>
<td>Size Attributes</td>
<td>Design Type</td>
<td>Fit Type</td>
<td>Price</td>
<td>Return</td>
<td>Pincode Stock</td>
<td>Stock Status</td>
<td>Collection Link</td>
<td>Product Link</td>
<td>Clone</td>
<td>View</td>
<td>Edit</td>
<td>Delete</td>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"fetch.php",
type:"POST"
},
"columnDefs":[
{
"targets":[0,1,2,3,27,28,29,30],
"orderable":false,
},
],
});
$(document).on('click', '.view', function(){
var id = $(this).attr('id');
var options = {
ajaxPrefix: '',
ajaxData: {id:id},
ajaxComplete:function(){
this.buttons([{
type: Dialogify.BUTTON_PRIMARY
}]);
}
};
new Dialogify('fetch_single.php', options)
.title('View Product Details')
.showModal();
});
$('#add_data').click(function(){
var options = {
ajaxPrefix:''
};
new Dialogify('add_data_form.php', options)
.title('Add New Product')
.buttons([
{
text:'Cancle',
click:function(e){
this.close();
}
},
{
text:'Insert',
type:Dialogify.BUTTON_PRIMARY,
click:function(e)
{
var image_data = $('#images').prop("files")[0];
var form_data = new FormData();
form_data.append('images', image_data);
form_data.append('name', $('#name').val());
form_data.append('address', $('#address').val());
form_data.append('gender', $('#gender').val());
form_data.append('designation', $('#designation').val());
form_data.append('age', $('#age').val());
form_data.append('productname', $('#productname').val());
form_data.append('designation', $('#designation').val());
form_data.append('age', $('#age').val());
form_data.append('style', $('#style').val());
form_data.append('fabric', $('#fabric').val());
form_data.append('material', $('#material').val());
form_data.append('type', $('#type').val());
form_data.append('color_f', $('#color_f').val());
form_data.append('size_f', $('#size_f').val());
form_data.append('color_a', $('#color_a').val());
form_data.append('size_a', $('#size_a').val());
form_data.append('design_type', $('#design_type').val());
form_data.append('fit_type', $('#fit_type').val());
form_data.append('price_real', $('#price_real').val());
form_data.append('return_s', $('#return_s').val());
form_data.append('pincode_stock', $('#pincode_stock').val());
form_data.append('stock_status', $('#stock_status').val());
form_data.append('c_link', $('#c_link').val());
form_data.append('p_link', $('#p_link').val());
$.ajax({
method:"POST",
url:'insert_data.php',
data:form_data,
dataType:'json',
contentType:false,
cache:false,
processData:false,
success:function(data)
{
if(data.error != '')
{
$('#form_response').html('<div class="alert alert-danger">'+data.error+'</div>');
}
else
{
$('#form_response').html('<div class="alert alert-success">'+data.success+'</div>');
dataTable.ajax.reload();
}
}
});
}
}
]).showModal();
});
$(document).on('click', '.update', function(){
var id = $(this).attr('id');
$.ajax({
url:"fetch_single_data.php",
method:"POST",
data:{id:id},
dataType:'json',
success:function(data)
{
localStorage.setItem('name', data[0].name);
localStorage.setItem('address', data[0].address);
localStorage.setItem('gender', data[0].gender);
localStorage.setItem('productname', data[0].productname);
localStorage.setItem('designation', data[0].designation);
localStorage.setItem('age', data[0].age);
localStorage.setItem('style', data[0].style);
localStorage.setItem('fabric', data[0].fabric);
localStorage.setItem('material', data[0].material);
localStorage.setItem('type', data[0].type);
localStorage.setItem('color_f', data[0].color_f);
localStorage.setItem('size_f', data[0].size_f);
localStorage.setItem('color_a', data[0].color_a);
localStorage.setItem('size_a', data[0].size_a);
localStorage.setItem('design_type', data[0].design_type);
localStorage.setItem('fit_type', data[0].fit_type);
localStorage.setItem('price_real', data[0].price_real);
localStorage.setItem('return_s', data[0].return_s);
localStorage.setItem('pincode_stock', data[0].pincode_stock);
localStorage.setItem('stock_status', data[0].stock_status);
localStorage.setItem('c_link', data[0].c_link);
localStorage.setItem('p_link', data[0].p_link);
localStorage.setItem('images', data[0].images);
var options = {
ajaxPrefix:''
};
new Dialogify('edit_data_form.php', options)
.title('Edit Product')
.buttons([
{
text:'Cancle',
click:function(e){
this.close();
}
},
{
text:'Edit',
type:Dialogify.BUTTON_PRIMARY,
click:function(e)
{
var image_data = $('#images').prop("files")[0];
var form_data = new FormData();
form_data.append('images', image_data);
form_data.append('name', $('#name').val());
form_data.append('address', $('#address').val());
form_data.append('gender', $('#gender').val());
form_data.append('productname', $('#productname').val());
form_data.append('designation', $('#designation').val());
form_data.append('age', $('#age').val());
form_data.append('style', $('#style').val());
form_data.append('fabric', $('#fabric').val());
form_data.append('material', $('#material').val());
form_data.append('type', $('#type').val());
form_data.append('color_f', $('#color_f').val());
form_data.append('size_f', $('#size_f').val());
form_data.append('color_a', $('#color_a').val());
form_data.append('size_a', $('#size_a').val());
form_data.append('design_type', $('#design_type').val());
form_data.append('fit_type', $('#fit_type').val());
form_data.append('price_real', $('#price_real').val());
form_data.append('return_s', $('#return_s').val());
form_data.append('pincode_stock', $('#pincode_stock').val());
form_data.append('stock_status', $('#stock_status').val());
form_data.append('c_link', $('#c_link').val());
form_data.append('p_link', $('#p_link').val());
form_data.append('hidden_images', $('#hidden_images').val());
form_data.append('id', data[0].id);
$.ajax({
method:"POST",
url:'update_data.php',
data:form_data,
dataType:'json',
contentType:false,
cache:false,
processData:false,
success:function(data)
{
if(data.error != '')
{
$('#form_response').html('<div class="alert alert-danger">'+data.error+'</div>');
}
else
{
$('#form_response').html('<div class="alert alert-success">'+data.success+'</div>');
dataTable.ajax.reload();
}
}
});
}
}
]).showModal();
}
})
});
$(document).on('click', '.clone', function(){
var id = $(this).attr('id');
$.ajax({
url:"fetch_single_data.php",
method:"POST",
data:{id:id},
dataType:'json',
success:function(data)
{
localStorage.setItem('name', data[0].name);
localStorage.setItem('address', data[0].address);
localStorage.setItem('gender', data[0].gender);
localStorage.setItem('productname', data[0].productname);
localStorage.setItem('designation', data[0].designation);
localStorage.setItem('age', data[0].age);
localStorage.setItem('style', data[0].style);
localStorage.setItem('fabric', data[0].fabric);
localStorage.setItem('material', data[0].material);
localStorage.setItem('type', data[0].type);
localStorage.setItem('color_f', data[0].color_f);
localStorage.setItem('size_f', data[0].size_f);
localStorage.setItem('color_a', data[0].color_a);
localStorage.setItem('size_a', data[0].size_a);
localStorage.setItem('design_type', data[0].design_type);
localStorage.setItem('fit_type', data[0].fit_type);
localStorage.setItem('price_real', data[0].price_real);
localStorage.setItem('return_s', data[0].return_s);
localStorage.setItem('pincode_stock', data[0].pincode_stock);
localStorage.setItem('stock_status', data[0].stock_status);
localStorage.setItem('c_link', data[0].c_link);
localStorage.setItem('p_link', data[0].p_link);
localStorage.setItem('images', data[0].images);
var options = {
ajaxPrefix:''
};
new Dialogify('clone_data_form.php', options)
.title('Clone Product')
.buttons([
{
text:'Cancle',
click:function(e){
this.close();
}
},
{
text:'Clone',
type:Dialogify.BUTTON_PRIMARY,
click:function(e)
{
var image_data = $('#images').prop("files")[0];
var form_data = new FormData();
form_data.append('images', image_data);
form_data.append('name', $('#name').val());
form_data.append('address', $('#address').val());
form_data.append('gender', $('#gender').val());
form_data.append('productname', $('#productname').val());
form_data.append('designation', $('#designation').val());
form_data.append('age', $('#age').val());
form_data.append('style', $('#style').val());
form_data.append('fabric', $('#fabric').val());
form_data.append('material', $('#material').val());
form_data.append('type', $('#type').val());
form_data.append('color_f', $('#color_f').val());
form_data.append('size_f', $('#size_f').val());
form_data.append('color_a', $('#color_a').val());
form_data.append('size_a', $('#size_a').val());
form_data.append('design_type', $('#design_type').val());
form_data.append('fit_type', $('#fit_type').val());
form_data.append('price_real', $('#price_real').val());
form_data.append('return_s', $('#return_s').val());
form_data.append('pincode_stock', $('#pincode_stock').val());
form_data.append('stock_status', $('#stock_status').val());
form_data.append('c_link', $('#c_link').val());
form_data.append('p_link', $('#p_link').val());
form_data.append('hidden_images', $('#hidden_images').val());
form_data.append('id', data[0].id);
$.ajax({
method:"POST",
url:'clone_data.php',
data:form_data,
dataType:'json',
contentType:false,
cache:false,
processData:false,
success:function(data)
{
if(data.error != '')
{
$('#form_response').html('<div class="alert alert-danger">'+data.error+'</div>');
}
else
{
$('#form_response').html('<div class="alert alert-success">'+data.success+'</div>');
dataTable.ajax.reload();
}
}
});
}
}
]).showModal();
}
})
});
$(document).on('click', '.delete', function(){
var id = $(this).attr('id');
Dialogify.confirm("<h3 class='text-danger'><b>Are you sure you want to remove this Product?</b></h3>", {
ok:function(){
$.ajax({
url:"delete_data.php",
method:"POST",
data:{id:id},
success:function(data)
{
Dialogify.alert('<h3 class="text-success text-center"><b>Product has been deleted</b></h3>');
dataTable.ajax.reload();
}
})
},
cancel:function(){
this.close();
}
});
});
});
</script>
fetch.php
<?php
//fetch.php
include('database_connection.php');
$query = '';
$output = array();
$query .= "SELECT * FROM tbl_employees ";
if(isset($_POST["search"]["value"]))
{
$query .= 'WHERE name LIKE "%'.$_POST["search"]["value"].'%" OR designation LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY id DESC ';
}
if($_POST["length"] != -1)
{
$query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = '<button type="button" name="clone" id="'.$row["id"].'" class="btn btn-primary btn-xs clone">Clone</button>';
$sub_array[] = '<button type="button" name="view" id="'.$row["id"].'" class="btn btn-primary btn-xs view">View</button>';
$sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>';
$sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>';
$sub_array[] = $row["id"];
$sub_array[] = $row["name"];
$sub_array[] = $row["designation"];
$sub_array[] = $row["gender"];
$sub_array[] = $row["age"];
$sub_array[] = $row["productname"];
$sub_array[] = $row["address"];
$sub_array[] = $row["style"];
$sub_array[] = $row["fabric"];
$sub_array[] = $row["material"];
$sub_array[] = $row["type"];
$sub_array[] = $row["color_f"];
$sub_array[] = $row["size_f"];
$sub_array[] = $row["color_a"];
$sub_array[] = $row["size_a"];
$sub_array[] = $row["design_type"];
$sub_array[] = $row["fit_type"];
$sub_array[] = $row["price_real"];
$sub_array[] = $row["return_s"];
$sub_array[] = $row["pincode_stock"];
$sub_array[] = $row["stock_status"];
$sub_array[] = $row["c_link"];
$sub_array[] = $row["p_link"];
$sub_array[] = '<button type="button" name="clone" id="'.$row["id"].'" class="btn btn-primary btn-xs clone">Clone</button>';
$sub_array[] = '<button type="button" name="view" id="'.$row["id"].'" class="btn btn-primary btn-xs view">View</button>';
$sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>';
$sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>';
$data[] = $sub_array;
}
function get_total_all_records($connect)
{
$statement = $connect->prepare("SELECT * FROM tbl_employees");
$statement->execute();
$result = $statement->fetchAll();
return $statement->rowCount();
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $filtered_rows,
"recordsFiltered" => get_total_all_records($connect),
"data" => $data
);
echo json_encode($output);
?>