我有四个X.Editable链接我想将它们提交到同一个URL如何将每个x.editable分配给该值以使每个值具有正确的值
这是可编辑的链接
<a href="javascript:;" id="CreditOfficer" name="CreditOfficer" data-name="CreditOfficer" data-type="text" data-pk="1"
data-original-title="Enter Name"> superuser </a>
<a href="javascript:;" id="ProgramManager" name="ProgramManager" data-name="ProgramManager" data-type="text" data-pk="2"
data-original-title="Enter Name"> superuser </a>
<a href="javascript:;" id="FinancialDirector" name="FinancialDirector" data-name="FinancialDirector" data-type="text" data-pk="3"
data-original-title="Enter Name"> superuser </a>
<a href="javascript:;" id="FoundationDirector" name="FoundationDirector" data-name="FoundationDirector" data-type="text" data-pk="4"
data-original-title="Enter Name"> superuser </a>
这是JQuery代码:
var initEditables = function() {
//set editable mode based on URL parameter
if (App.getURLParameter('mode') == 'inline') {
$.fn.editable.defaults.mode = 'inline';
$('#inline').attr("checked", true);
} else {
$('#inline').attr("checked", false);
}
//global settings
$.fn.editable.defaults.inputclass = 'form-control';
$.fn.editable.defaults.url = 'foundationofficialsajax.php';
$('#CreditOfficer').editable({
validate: function(value) {
if ($.trim(value) == '') return 'هذا الحقل مطلوب';
},
type: 'text',
pk: 1,
name: 'CreditOfficer',
title: 'heeelp'
});
$('#ProgramManager').editable({
validate: function(value) {
if ($.trim(value) == '') return 'هذا الحقل مطلوب';
},
type: 'text',
pk: 1,
name: 'ProgramManager',
title: 'heeelp'
});
$('#FinancialDirector').editable({
validate: function(value) {
if ($.trim(value) == '') return 'هذا الحقل مطلوب';
},
type: 'text',
pk: 1,
name: 'FinancialDirector',
title: 'heeelp'
});
$('#FoundationDirector').editable({
validate: function(value) {
if ($.trim(value) == '') return 'هذا الحقل مطلوب';
},
type: 'text',
pk: 1,
name: 'FoundationDirector',
title: 'heeelp'
});
}
这里是我要提交值的php URL:
<?php
$constantsobj = new constants();
$helpersobj = new helpers();
$manger_sth = $constantsobj->getfoundationofficials();
$manger_row = $manger_sth->fetch();
$CreditOfficer_value =$manger_row["CreditOffice"];
$ProgramManager_value =$manger_row["ProgramManager"];
$FinancialDirector_value =$manger_row["FinancialDirector"];
$FoundationDirector_value =$manger_row["FoundationDirector"];
$pk = $_GET['pk'];
$CreditOfficer_name = isset($_POST["CreditOfficer"]) ?$helpersobj->prepar_data($_POST['CreditOfficer']):"";
$CreditOfficer_value = $_POST['CreditOfficer'];
$ProgramManager_name = isset($_POST["ProgramManager"]) ?$helpersobj->prepar_data($_POST['ProgramManager']):"";
$ProgramManager_value = $_POST['ProgramManager'];
$FinancialDirector_name = isset($_POST["FinancialDirector"]) ?$helpersobj->prepar_data($_POST['FinancialDirector']):"";
$FinancialDirector_value = $_POST['FinancialDirector'];
$FoundationDirector_name= isset($_POST["FoundationDirector"]) ?$helpersobj->prepar_data($_POST['FoundationDirector']):"";
$FoundationDirector_value = $_POST['FoundationDirector'];
$status =$constantsobj->updatefoundationofficials($CreditOfficer_value , $ProgramManager_value ,$FinancialDirector_value ,$FoundationDirector_value);
?>
我想将每个不同的值提交到同一个网址,我该怎么做。
答案 0 :(得分:0)
以下是有人需要它的答案 使用选择器以分开的方式访问每个链接
function bind_editable_to_column(table_selector,column_selector,ajax_url,title,options) {
options = typeof options !== 'undefined' ? options : '';
$(table_selector).editable({
selector: column_selector,
url: ajax_url,
title: title,
ajaxOptions: {
type: 'POST',
dataType: 'json'
},
source: options
});
}
和ajax将是这样的:
<?php
$employee_id = trim($_POST['pk']);
$column_name = trim($_POST['name']);
$value = trim($_POST['value']);
$result['response']['success'] = true;
$result['response']['message'] = "Updated the $column_name with $value";
echo json_encode($result);
if(strlen($employee_id) > 0 && strlen($column_name) > 0 && strlen($value) > 0) {
//connecting to database
try {
$pdo = new PDO("mysql:host=localhost;dbname=YOUR_DB_NAME","YOUR_USER_NAME","YOUR_PASSWORD");
}
catch(PDOException $e) {
echo $e->getMessage();
}
$query = "UPDATE `tbl_employees` SET {$column_name} = :value WHERE `id`=:id";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':value',$value);
$stmt->bindParam(':id',$employee_id);
if($stmt->execute()) {
//header('HTTP 200 OK', true, 200);
$result['response']['success'] = true;
$result['response']['message'] = "Updated the $column_name with $value";
echo json_encode($result);
}
else {
header('HTTP 400 Bad Request', true, 400);
echo "Error: Unable to update";
}
}
else {
header('HTTP 400 Bad Request', true, 400);
echo "One or more required values are missing.";
}
?>
取决于这篇文章: x.Editable to whole database table