gpt4 book ai didi

php - 使用 jQuery 和 PHP 发送和接收 AJAX 请求

转载 作者:行者123 更新时间:2023-11-29 18:25:41 26 4
gpt4 key购买 nike

我正在尝试向页面发送 AJAX 请求以解释某些数据,如果它符合我正在寻找的内容,请发回另一个 AJAX 请求。现在我可以看到第一个请求正在发出,但我没有得到回复

//message.php
<head>
<script>
function org_name(str){
alert(str); //this alert appears, so I know the data is being received by this function
$.get("common_functions.php", { group_name: str} );
}
</script>
</head>

然后,在 common_functions.php 上,我收到了类似的请求,但是,我不确定到底是什么问题。警告框甚至没有出现,所以我很困惑为什么控制台会说请求已发送

//common_functions.php

if(isset($_GET['group_name'])){
?>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
alert('common_functions'); //this does not appear
$.get("message.php", { name: "test"} );
</script>
<?
}

当我在 chrome 中打开 javascript 控制台时,我看到请求已发送表单消息到 common_functions,但显然 common_functions 上的请求没有发回

//text from javascript console
Request URL:http://localhost/message/common_functions.php?group_name=test
Request Method:GET
Status Code:200 OK

有没有人看到我做错或遗漏的明显事情?如果它有所不同,common_functions 包含在 message.php 中,因为我确实为我的 php 使用了该页面中的一些其他函数。

最佳答案

你必须对你的数据做点什么。现在,您正在进行 AJAX 调用,但对您的数据不做任何事情。

所以像下面这样的东西会起作用:

$.ajax({
url: "common_functions.php",
data: { group_name: str },
type: "GET",
success: function (data) {
$(data).appendTo("head");
}
});

关于php - 使用 jQuery 和 PHP 发送和接收 AJAX 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545376/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com