【问题标题】:How to submit more than one x.editable to the same URL如何向同一个 URL 提交多个 x.editable
【发布时间】:2018-05-19 23:08:40
【问题描述】:

我有四个 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);
    ?>

我想将每个不同的值提交到同一个 URL,我该怎么做。

【问题讨论】:

    标签: php jquery json ajax twitter-bootstrap


    【解决方案1】:

    如果有人需要,这里是答案 使用选择器访问每个单独的链接

    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

    【讨论】:

      猜你喜欢
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 2017-06-13
      • 2020-11-03
      • 2014-10-14
      • 2021-02-14
      • 1970-01-01
      相关资源
      最近更新 更多