Page要素は次のように定義されています。PHPスクリプトでページ要素を更新する
<div id="readf" class="tabbertab">
<h2>First Reading</h2>
<div id='titlefe' class='rtitle'>
</div>
<div id='readfe' class='rtext'>
</div>
</div>
これらのページ要素にデータを追加するためにphpスクリプトへのajax呼び出しを行います。
<script>
$('#readings').ready(function(){
$.ajax({
url: "loadenglish.php",
type: "GET",
data: { },
cache: false,
async: true,
success: function (response) {
if (response != '')
{
alert (response);
}
},
error: function (request, status, error) {
alert ("status "+status+" error "+error+"responseText "+request.responseText);
},
});
});
</script>
phpスクリプトはデータを取得し、スクリプトエコーでデータを追加します。
<?php
$titlefe = 'text 1';
$readfe = 'text 2';
echo "<script type='text/javascript'> $('#titlefe').append('".$titlefe."'); $('#readfe').append('".$readfe."'); </script>";
?>
警告文は、phpスクリプトが正しい情報を取得することを示しています。しかし、ページ要素は更新されません。要素ID titlefe
に$titlefe
を追加する別の方法はありますか?
これは、 'datatype: 'json''を含むようにajax呼び出しを更新すると機能します。そして、私はページ要素の 'response.titlefe'と' response.readfe'で情報を取り出すことができます。ありがとう。 – user823527