私は少し混乱があると思います。多くの開発者は最初、javascript がクライアント側でレンダリングされ、テンプレート (あなたの場合は php コード) がサーバー側でレンダリングされることを理解していません。
どういう意味ですか?
これは、サーバーが HTML 文字列をブラウザーに出力する php コードを実行していることを意味します。この HTML 文字列には、javascript を含むスクリプト セグメントが含まれています。PHPコードが完了すると、コードはサーバーを離れ、ネットワークを介してブラウザに移動します。ブラウザーに到達すると、ブラウザーはどのコードが HTML を生成したかを認識しません。静的リソースでもかまいません。
ユーザー入力で php コードを実行するには、ユーザー入力がサーバーに戻る必要があります。また、コード出力をユーザーに表示するには、出力をサーバーからブラウザに戻す必要があります。
この往復は、2 つの方法のいずれかで行われます。1 つ目は、ページ全体を更新するフォームです (このケースには適していません)。もう 1 つは AJAX です。
AJAX is a way to send small pieces of information to the server, render them on server side, and get them back after rendering into a javascript function. It's kind of like turning the textarea input to a "php string".
What will actually happen is - you will send the text area input to the server, the server will render a php template ( in which it will simply operate the "mysql_real_escape_string" function on the data ) , the rendered result will get back to a javascript callback, and then you can please it in the "preview" div.
Here a cool tutorial I found about ajax and php using jquery. ( use jquery )
Hope this helps.
The javaspcript code should look something like the following
$.ajax({ 'url' : '/render-string-for-preview',
'type':'post',
'data' : { 'text' : $("textarea").val() },
'success' : function(result) { $("#input_excercise").html( result ) }
});
そして、「/render-string-for-preview」にリソースを追加する必要があります。これは、単に次のようなことを行います(php開発者ではありません...)
<? mysql_real_escape_string ( POST["text"]) ?>
以上です....