1

ユーザーが選択リストから templateId を選択してから、データベースにクエリを実行して templateId に基づいてテンプレートのコンテンツを取得するようにします。次に、テンプレート コンテンツをテキストエリアに表示したいのですが、デザイン (ビュー) を表示するのではなく、TinyMCE テキストエリアに html タグを表示します。

ページの読み込み時に同じ templateContents を表示する場合にのみ機能しますが、データベースから取得して同じコンテンツを表示しようとすると失敗します。

それがすべて、私が必要としたものの手がかりになることを願っています.

ステップ1では、コードは正常に機能しています...

<textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 50%">
    <?php echo htmlspecialchars($ResultArray[0]['Contents']); ?>
</textarea>

...しかし、選択した値を変更すると、選択したテンプレートを呼び出しています:

<select name="templateId" id="templateId" onchange="GetTemplateView(this.value);">
    <?php for($i=0; $i<count($ResultArray); $i++){ ?>
    <option value="<?php echo $ResultArray[$i]['TemplateId']; ?>"><?php echo $ResultArray[$i]['Name']; ?></option>
    <?php }?>
</select> 

Ajax リクエストは次のとおりです。

function GetTemplateView(templateId)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {   // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else
    {   // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            if (navigator.appName == 'Microsoft Internet Explorer')
                document.getElementById("templateView").outerHTML = xmlhttp.responseText;
            else
                document.getElementById("templateView").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "js/GetTemplateView.php?id=" + templateId + "&encode=true", true);
    xmlhttp.send();
}

GetTemplateView.php:

<?php
include_once("../classes/db_utility_class.php");
$ClassObj= new Cdb();
$input        =   $_GET["id"];
$Encode       =   $_GET["encode"];

if($input!=0)
{
    $query = "SELECT Contents FROM mailtemplate WHERE TemplateId=".$input;
    $result = $ClassObj->getRowFromDB($query);
    if($result != "Error in query" || $result != "No Record Found")
    {
        if($Encode)
        {
            echo '<textarea id="ele1" name="ele1" rows="15" cols="80" style="width: 50%">';
            echo htmlspecialchars($result['Contents']);
            echo '</textarea>';
        }
        else
            echo $result['Contents'];
    }
}
?> 
4

1 に答える 1

0

まず、より使いやすい jquery.ajax を使用します。

1. tinyMCE を processpage.php の変数に格納します。

  1. そして、ajax 呼び出しの成功関数で、それを表示したい div または body に追加します。

サンプル コードを参照してください。必要に応じて呼び出してください。

<script>
             $.ajax({
                url: processpage.php, 
                type: 'GET',                     
                contentType: 'text/html',
                dataType: 'text',
                async: false,
                data:{
                                    showTINYMCE : 'Yes'
                                },
                success: function(msg)
                {
                    $('body').append(msg);
                },
                error: function (msg) 
                {
                }
            });

</script>

あなたの processpage.php で:

if($_GET['showTINYMCE'] == 'Yes')
{
$tinymce = "contains the tinymce";     
echo $tinymce;
}

これでできます。

于 2013-02-22T13:31:55.277 に答える