【问题标题】:PHP JQuery Ajax Inline Editing with select option带有选择选项的 PHP JQuery Ajax 内联编辑
【发布时间】:2016-11-07 14:43:25
【问题描述】:

我正在使用一个 php jquery ajax 内联编辑系统,它按照预期的方式工作,直到我添加一个选择选项列表。下面是我正在处理的项目中的 jquery 和 php/html 布局,无论我尝试了什么,除了选择选项之外,每个都正确保存到数据库中。

<script>
function showEdit(editableObj) {
    $(editableObj).css("background","#FFF");
} 

function saveToDatabase(editableObj,column,id) {
    $(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
    $.ajax({
        url: "update_door_schedule.php",
        type: "POST",
        data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
        success: function(data){
            $(editableObj).css("background","#FDFDFD");
        }        
    });
}

<td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Date and Time Entered]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Date and Time Entered']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Door Number]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Door Number']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Customer Xref]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Customer Xref']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Interior or Exterior]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);">
            <select class="input-clearfit">
                <?php if($schedule_row['Interior or Exterior'] > ' '){ ?>
                    <option value="<?php echo $schedule_row['Interior or Exterior']; ?>" selected="selected"><?php echo $schedule_row['Interior or Exterior']; ?></option>
                <?php } ?>  
                <option value=""></option>
                <?php $result = sqlsrv_query($conn, "SELECT Product, [Sort Sequence]
                FROM DD_Product
                ORDER BY [Sort Sequence]"); 
                while ($list_row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { ?>
                    <option value="<?php echo $list_row['Product']; ?>"><?php echo $list_row['Product']; ?></option>
                <?php } ?>     
            </select>
        </td>

【问题讨论】:

  • 会发生什么?根本没救吗?检查数据库?检查您的日志文件?保存了错误的数据?错误信息?更多细节,请...
  • 所有时都可以保存到db,但选择选择选项时没有更改。 span>
  • 我没有看到实际选择框的任何事件?假设会发生什么?
  • when the option is selected it should trigger the onBlur event to saveToDatabase ... the preceeding td's all post to the db on change.我已经尝试将 onblur 和 onclick 移动到选择中,但这也不起作用。
  • 选择一个选项不会触发 onBlur。测试:onchange 改为选择框。

标签: php jquery sql-server ajax inline


【解决方案1】:

经过几个不同的变化和大量的谷歌搜索,答案就在我面前......

将 innerhtml() 替换为 val() 并在 td 中放置输入字段和/或选择选项菜单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 2020-04-24
    相关资源
    最近更新 更多