我试图从 2 小时内解决这个问题,但没有运气,也许这不是技术性的,但我需要帮助!
我有一个 AJAX 脚本,需要将 GET 请求发送到同一页面上的 php 脚本。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。我不确定我是否必须发布其他代码。如果您需要了解更多信息,请询问,我会尽快回复。