PHP+;JAVASCRIPT保存数据

PHP+;JAVASCRIPT保存数据,php,jquery,json,Php,Jquery,Json,这是控制器: public function routeupdateAction() { $iRoute = IV_Http_Base::getParameter( 'id', IV_Http_Base::HTTP_POST ); $sPath = IV_Http_Base::getParameter( 'path', IV_Http_Base::HTTP_POST ); $sModule = IV_Http_Base::getParameter( 'module',

这是控制器:

 public function routeupdateAction() {
    $iRoute = IV_Http_Base::getParameter( 'id', IV_Http_Base::HTTP_POST );
    $sPath = IV_Http_Base::getParameter( 'path', IV_Http_Base::HTTP_POST );
    $sModule = IV_Http_Base::getParameter( 'module', IV_Http_Base::HTTP_POST );
    $sController = IV_Http_Base::getParameter( 'controller', IV_Http_Base::HTTP_POST );
    $sAction = IV_Http_Base::getParameter( 'action', IV_Http_Base::HTTP_POST );
    $iAccessRole = IV_Http_Base::getParameter( 'accessRole', IV_Http_Base::HTTP_POST );
    $iRoleCompareOperator = IV_Http_Base::getParameter( 'roleCompareOperator', IV_Http_Base::HTTP_POST );

    $oRoute = Default_Model_RouteEntity::getInstanceById( $iRoute );
    if( is_object( $oRoute ) && $oRoute instanceof Default_Model_RouteEntity ) {
        $oRoute->setPath( $sPath );
        $oRoute->setModule( $sModule );
        $oRoute->setController( $sController );
        $oRoute->setAction( $sAction );
        $oRoute->setAccessRole($iAccessRole);
        $oRoute->setRoleCompareOperator($iRoleCompareOperator);
        $oRoute->save();

        $aReturn = array( 'valid' => 'true' );
    } else  {
        $aReturn = array( 'valid' => 'false' );
    }
        echo json_encode( $aReturn );
    }
}
route.js文件

var ROUTE = new function () {
    var oGlobal = this;
    this.sSaveUrl = '';

    this.setSaveUrl = function (_sUrl) {
        this.sSaveUrl = _sUrl;
    }

    this.setEventSubmit = function () {
        $('[id^="route_update"]').each(function () {
            $(this).click(function () {
                var oData = $(this).closest('tr').find('input').serializeArray();
                console.log(oData);

                oReq = $.post(oGlobal.sSaveUrl, oData, function (data) {
                    if (data['valid'] != "true") {
                        //console.log('error');
                        //Fade in
                        $('#comment').html('Insert Success').fadeIn(1000);
                        //Fade out
                        setTimeout(function () {
                            $('#comment').html('').fadeOut(1000);
                        }, 1500);
                        //fade in
                        $('#comment')
                    } else {
                        // console.log('success');
                        //Fade in
                        $('#comment').html('Insert Success').fadeIn(1000);
                        //Fade out
                        setTimeout(function () {
                            $('#comment').html('').fadeOut(1000);
                        }, 1500);
                        //fade in
                        $('#comment')
                    }
                    return false;
                }, 'json');

                return false;
            });
        });
    }

    this.init = function () {
        this.setEventSubmit();
    }
}
还有html标记

<form class="form-inline" role="form">
      <form class="well form-inline">
<table class="table table-bordered" width="100%">
    <tr>
        <th width="13%">Path</th>
        <th width="13%">Module</th>
        <th width="13%">Controller</th>
        <th width="13%">Action</th>
        <th width="13%">Access Role</th>
        <th width="13%">Compare Operator</th>
        <th width="9%">Submit</th>
    </tr>
    <?
    $aRoutes = $this->getValue('aRoutes');
    if( count($aRoutes) == 0 ) {
        ?>
        <tr>
            <td colspan="7">No routes found!</td>
        </tr>
    <?
    } else {
        /**
         * @var Default_Model_RouteEntity $oRoute
         */
        foreach ( $aRoutes as $oRoute) {
            ?>
            <tr>
                <td width="13%">
                    <input type="text" name="path" value="<?= $oRoute->getPath(); ?>"/>
                </td>
                <td width="13%">
                    <input type="text" value="<?= $oRoute->getModule(); ?>"/>
                </td>
                <td width="13%">
                    <input type="text" value="<?= $oRoute->getController(); ?>"/>
                </td>
                <td width="13%">
                    <input type="text" value="<?= $oRoute->getAction(); ?>"/>
                </td>
                <td width="13%">
                    <input type="text" class="form-actions" value="<?= $oRoute->getAccessRole(); ?>"/>
                </td>
                <td width="13%">
                    <input type="text" value="<?= $oRoute->getRoleCompareOperator(); ?>"/>
                </td>
                <td width="9%">
                    <input type="hidden" name="id" value="<?= $oRoute->getId(); ?>" />
                    <button type="button" class="btn btn-default btn-sm" id="route_update">Edit</button>
                    <div id="comment"></div>
                </td>
            </tr>
        <?
        }
    } ?>
</table>
      </form>
</form>
<? $this->addJs('admin/cms/route'); ?>
<script type="text/javascript">
    $(document).ready(function () {
        ROUTE.setSaveUrl('<?=IV_Url_Base::url( 'admin_cms_routeupdate' ); ?>');
        ROUTE.init();
    });
</script>

路径
模块
控制器
行动
访问角色
比较运算符
提交
没有找到路线!
  • 删除“表单”标签
  • 使用jQuery在按钮上设置onclick事件
  • 使用
    parent('tr')
    ()检索行元素
  • 使用row元素遍历
    td
    标记并将数据保存到某个数组:
    $('td',$row).each(函数(){/*解析td元素*/})
  • 使用将数组发送到PHP脚本
  • 将数据保存在PHP脚本中,并使用(200-OK,4**-ERROR)将结果显示到AJAX
  • 如果一切正常,请使用jQuery制作所需的动画

  • 好的,我看到您也在使用jQuery。所需的代码不仅仅是一个片段,而且,您希望将其保存在哪里?在数据库中?文本文件?您自己格式的二进制文件?需要将其保存到数据库中。。。