Form を使って PHP ファイルを読み込み、ページ全体を書き直すという手段もありますが、ある関数だけを呼び出したいときなど、ajax を使うと PHP 関数を呼び出してページ側で返り値を得ることができます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fill() | |
{ | |
$.ajax({ | |
url:'fillin.php', | |
success: function (results) { | |
$('textarea#text').html(results); | |
}, | |
error: function () { | |
}, | |
}); | |
return false; | |
} |
PHP ファイル側では、渡したい値を echo などで表示します。
これで PHP の関数をページから呼び出すことができます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
echo <<<END: | |
line a | |
line b | |
line c | |
END; | |
?> |