Tooltipster popup和php switch case

时间:2018-04-04 00:34:29

标签: javascript php jquery ajax

我试图通过将通常需要重新加载页面的所有功能移动到ajax弹出窗口来改善网页的用户体验。除了一个功能外,我在所有功能上都取得了成功。 我拿了原始的php文件并通过交互式工具提示中的AJAX调用它。我遇到的问题是这个文件有很多按钮,点击时选择php switch语句中的特定情况。

其中一个原始按钮后面的html示例是

<a href="http://localhost/devarea/devadmin/image_handler.php?products_filter=313&amp;action=layout_edit"><img src="includes/languages/english/images/buttons/button_edit.gif" border="0" alt="IH_IMAGE_EDIT" title=" IH_IMAGE_EDIT "></a>

然后会调用

case 'layout_edit':
                // Edit specific details 
                $imgNameStr = '&amp;imgEdit=1' . '&amp;imgBase=' . $products_image_base
                                               . "&amp;imgSuffix=" . $selected_image_suffix
                                               . "&amp;imgBaseDir=" . $products_image_directory 
                                               . "&amp;imgExtension=" . $selected_image_extension;
                $heading[] = array(
                    'text' => '<strong>' . TEXT_INFO_EDIT_PHOTO . '</strong>'
                );
.... //more code in here
break;

我希望做的是使用AJAX,jQuery或Javascript在单击按钮时调用相关案例,保存显示的div的当前内容,显示案例生成的内容,然后处理后恢复原始内容。我希望解决方案不要求在可能的情况下将每个开关盒的内容移动到新文件中。

虽然我知道如何保存当前内容并将其恢复,但我不知道我是否可以通过切换案例做我想做的事。

使用AJAX,jQuery还是Javascript,这是否可能? 有关资源和阅读的一些指示非常有用,因为我在谷歌上的搜索还没有发现任何有用的东西。

根据ArtisiticPhoenix

的要求添加了整个开关
switch ($action) {
            case 'layout_edit':
                // Edit specific details 
                $imgNameStr = '&amp;imgEdit=1' . '&amp;imgBase=' . $products_image_base
                                               . "&amp;imgSuffix=" . $selected_image_suffix
                                               . "&amp;imgBaseDir=" . $products_image_directory 
                                               . "&amp;imgExtension=" . $selected_image_extension;
                $heading[] = array(
                    'text' => '<strong>' . TEXT_INFO_EDIT_PHOTO . '</strong>'
                );

            case 'layout_new':  
                if ( $action != 'layout_edit' ) {
                    $imgNameStr .= ( $no_images ) ? "&amp;newImg=1" : '&amp;imgBase='.$products_image_base
                                                                    . "&amp;imgBaseDir=" . $products_image_directory 
                                                                    . "&amp;imgExtension=" . $default_extension;
                    $heading[] = array(
                        'text' => '<strong>' . TEXT_INFO_NEW_PHOTO . '</strong>'
                    );
                }

                $contents = array(
                    'form' => zen_draw_form('image_define', FILENAME_IMAGE_HANDLER, 
                                            '&products_filter=' . $products_filter . $imgNameStr
                                          . '&amp;action=save', 'post', 'enctype="multipart/form-data"')
                ); //steve check this &products_filter=

                // check if this is a master image or if no images exist
                if ($no_images) {
                    $contents[] = array(
                        'text' => '<strong>' . TEXT_INFO_IMAGE_BASE_NAME . '</strong><br />' 
                    );
                    $contents[] = array(
                        'text' => zen_draw_input_field('imgBase', '', 'size="30"')
                    );

                    $dir = @dir(DIR_FS_CATALOG_IMAGES);
                    $dir_info[] = array('id' => '', 'text' => TEXT_INFO_MAIN_DIR);
                    while ($file = $dir->read()) {
                        if (is_dir(DIR_FS_CATALOG_IMAGES . $file) 
                            && strtoupper($file) != 'CVS' 
                            && $file != "." 
                            && $file != ".." 
                            && $file != 'original' 
                            && $file != 'medium'
                            && $file != 'large') {
                            $dir_info[] = array('id' => $file . '/', 'text' => $file);
                        }
                    }
                    $contents[] = array('
                        text' => '<br /><strong>' . TEXT_INFO_BASE_DIR . '</strong><br />' . TEXT_INFO_NEW_DIR
                    );
                    $contents[] = array(
                        'text' => TEXT_INFO_IMAGE_DIR . zen_draw_pull_down_menu('imgBaseDir', $dir_info, "")
                    );
                    $contents[] = array(
                        'text' => TEXT_INFO_OR.' ' . zen_draw_input_field('imgNewBaseDir', '', 'size="20"') 
                    );
                } else if ($action != 'layout_edit') {
                    $contents[] = array(
                        'text' => '<strong>' . TEXT_INFO_IMAGE_SUFFIX . '</strong><br />' . TEXT_INFO_USE_AUTO_SUFFIX . '<br />' 
                    );
                    $contents[] = array(
                        'text' => zen_draw_input_field('imgSuffix', $selected_image_suffix, 'size="10"') 
                    );
                }

                // -----
                // Set up the "acceptable" file types for the form, depending on whether or not the active product
                // currently has an image defined.
                //
                if ($no_images) {
                    $accept = 'image/jpeg,image/jpg,image/gif,image/png';
                } else {
                    switch (strtolower($products_image_extension)) {
                        case '.gif':
                            $accept = 'image/gif';
                            break;
                        case '.png':
                            $accept = 'image/png';
                            break;
                        case '.jpg':        //-Fall-through ...
                        case '.jpeg':
                            $accept = 'image/jpeg,image/jpg';
                            break;
                        default:
                            $accept = 'image/jpeg,/image/jpg,image/gif,image/png';
                            break;
                    }
                }
                $file_parms = 'accept="' . $accept . '"';

                // Image fields
                if ( $action == 'layout_new' ) {// display warning on edit screen that the default file must be filled in
                    //-------------------------
                    $contents[] = array(
                        'text' => '<br /><strong>' . TEXT_INFO_DEFAULT_IMAGE . '</strong>&nbsp;&nbsp;<strong class="errorText">(required)</strong><br />' 
                            . TEXT_INFO_DEFAULT_IMAGE_HELP . '<br />'
                            . zen_draw_input_field('default_image', '', 'size="20" ' . $file_parms, false, 'file') . '<br />' . $pInfo->products_image
                    );
                } else {
                    $contents[] = array(
                        'text' => '<br /><strong>' . TEXT_INFO_DEFAULT_IMAGE . '</strong><br />' 
                            . TEXT_INFO_DEFAULT_IMAGE_HELP . '<br />'
                            . zen_draw_input_field('default_image', '', 'size="20" '. $file_parms, false, 'file') . '<br />' . $pInfo->products_image
                    );
                }
                $contents[] = array(
                    'text' => '<br /><strong>' . TEXT_MEDIUM_FILE_IMAGE . '</strong><br />' . zen_draw_input_field('medium_image', '', 'size="20" ' . $file_parms, false, 'file') . '<br />'
                );
                $contents[] = array(
                    'text' => '<br /><strong>' . TEXT_LARGE_FILE_IMAGE . '</strong><br />' . zen_draw_input_field('large_image', '', 'size="20" ' . $file_parms, false, 'file') . '<br />'
                );
                $contents[] = array(
                    'align' => 'center', 
                    'text' => '<br />' . zen_image_submit('button_save.gif', IMAGE_SAVE) 
                );
                break;



            default:
                $heading[] = array(
                    'text' => '<strong>' . TEXT_INFO_SELECT_ACTION . '</strong>'
                );
                $contents = array(
                    'align' => 'center', 
                    'form' => zen_draw_form('image_define', FILENAME_IMAGE_HANDLER, 'ih_page=' . $ih_page . '&amp;products_filter=' . $products_filter . '&amp;action=save', 'post', 'enctype="multipart/form-data"')
                );
                // show new, delete, and edit buttons
                $contents[] = array(
                    'align' => 'center', 
                    'text' => '<br />' .
                        ' <a href="' . $ih_admin->imageHandlerHrefLink($_GET['imgName'], $products_filter, 'layout_edit') . '">'
                        . zen_image_button('button_edit.gif', IH_IMAGE_EDIT) . '</a> &nbsp; '
                        . ' <a href="' . $ih_admin->imageHandlerHrefLink($_GET['imgName'], $products_filter, 'layout_delete') . '">'
                        . zen_image_button('button_delete.gif', IMAGE_DELETE) . '</a> &nbsp;'
                        . ' <a href="' . $ih_admin->imageHandlerHrefLink('', $products_filter, 'layout_new') . '">'
                        . zen_image_button('button_new_file.gif', IH_IMAGE_NEW_FILE) . '</a> &nbsp;'
                        . ' <input id="close-tooltip" type="button" value="Cancel" alt="Cancel" title="Cancel"/>'
                );
                $contents[] = array();
                break;
        }

0 个答案:

没有答案