運が悪いので、2時間からこれを理解しようとしています。おそらくそれほど技術的ではありませんが、助けが必要です!
同じページにあるphpスクリプトにGETリクエストを送信する必要があるAJAXスクリプトがあります。PHPスクリプトは次のように終了します
if ($success) {
print( $state );
}?>
Javascript は php ターミネーションのすぐ下にあり、これです。
<script>
$('table button').click( function() {
var button = $(this);
/* if button inside the table is clicked */
var username = button.parent().parent().children('td').html();
var state = button.html();
/* send GET request */
$.ajax({
type: "GET",
url: 'index.php',
data: 'username='+username+'&state='+state,
success: function(response) {
alert(response);
}
});
});
</script>
理解できないのは、なぜこのテキストを含むアラートが表示されるのかということです
inside // this is the state, so it's good
<script> // this is the script, not good
$('table button').click( function() {
var button = $(this);
/* if button inside the table is clicked */
var username = button.parent().parent().children('td').html();
var state = button.html();
/* send GET request */
$.ajax({
type: "GET",
url: 'index.php',
data: 'username='+username+'&state='+state,
success: function(response) {
alert(response);
}
});
});
</script>
PHPコードから得られる厄介な応答のために、それを行うことができないため、成功時にHTMLを操作する必要があります。他のコードを投稿する必要があるかどうかはわかりません。もっと詳しく知りたい場合は、質問してください。できるだけ早く返信します。