Jquery y@ADyson:
或者,您可以使PHP更复杂一点,至少返回 一些不同的测试数据取决于发送给它的数据值Jquery y@ADyson:,jquery,html,ajax,Jquery,Html,Ajax,或者,您可以使PHP更复杂一点,至少返回 一些不同的测试数据取决于发送给它的数据值 <script> $(document).ready(function() { $('a.themafeest').click(function() { var datalist = $(this).data().value; $.ajax({ type: "POST",
<script>
$(document).ready(function() {
$('a.themafeest').click(function() {
var datalist = $(this).data().value;
$.ajax({
type: "POST",
url: "/puurfeesten/wp-content/themes/puurfeesten-theme/change-loop.php",
data:{datalist:datalist},
success: function(response) {
if ($("#data_goes_here").html() != response) {
$("#data_goes_here").fadeOut(200, function() {
$("#data_goes_here").html(response);
$("#data_goes_here").fadeIn();
console.log(datalist);
});
}
}
});
return false;
});
});
</script>
让php返回发送给它的值
<script>
$(document).ready(function() {
$('a.themafeest').click(function() {
var datalist = $(this).data().value;
$.ajax({
type: "POST",
url: "/puurfeesten/wp-content/themes/puurfeesten-theme/change-loop.php",
data:{datalist:datalist},
success: function(response) {
if ($("#data_goes_here").html() != response) {
$("#data_goes_here").fadeOut(200, function() {
$("#data_goes_here").html(response);
$("#data_goes_here").fadeIn();
console.log(datalist);
});
}
}
});
return false;
});
});
</script>
$(文档).ready(函数(){
$('a.themafeest')。单击(函数(){
var datalist=$(this).data().value;
$.ajax({
类型:“POST”,
url:“/puurfeesten/wp content/themes/puurfeesten theme/change loop.php”,
数据:{datalist:datalist},
成功:功能(响应){
if($(“#数据_转到这里”).html()!=响应){
$(“#数据(此处为)”).fadeOut(200,function(){
$(“#这里有数据”).html(响应);
$(“这里有数据”).fadeIn();
console.log(数据列表);
});
}
}
});
返回false;
});
});
然后在change-loop.php中
<?php
echo $_POST['datalist'];
?>
您从未看到所选值的原因是,在
更改循环.php
中,您回显“hello”
并且在任何给定时间都不会更改,您需要回显来自请求的数据。这样你就会看到变化
要对@ADyson的评论添加更多内容,请执行以下操作:
或者,您可以使PHP更复杂一点,至少返回
一些不同的测试数据取决于发送给它的数据值
<script>
$(document).ready(function() {
$('a.themafeest').click(function() {
var datalist = $(this).data().value;
$.ajax({
type: "POST",
url: "/puurfeesten/wp-content/themes/puurfeesten-theme/change-loop.php",
data:{datalist:datalist},
success: function(response) {
if ($("#data_goes_here").html() != response) {
$("#data_goes_here").fadeOut(200, function() {
$("#data_goes_here").html(response);
$("#data_goes_here").fadeIn();
console.log(datalist);
});
}
}
});
return false;
});
});
</script>
让php返回发送给它的值
<script>
$(document).ready(function() {
$('a.themafeest').click(function() {
var datalist = $(this).data().value;
$.ajax({
type: "POST",
url: "/puurfeesten/wp-content/themes/puurfeesten-theme/change-loop.php",
data:{datalist:datalist},
success: function(response) {
if ($("#data_goes_here").html() != response) {
$("#data_goes_here").fadeOut(200, function() {
$("#data_goes_here").html(response);
$("#data_goes_here").fadeIn();
console.log(datalist);
});
}
}
});
return false;
});
});
</script>
$(文档).ready(函数(){
$('a.themafeest')。单击(函数(){
var datalist=$(this).data().value;
$.ajax({
类型:“POST”,
url:“/puurfeesten/wp content/themes/puurfeesten theme/change loop.php”,
数据:{datalist:datalist},
成功:功能(响应){
if($(“#数据_转到这里”).html()!=响应){
$(“#数据(此处为)”).fadeOut(200,function(){
$(“#这里有数据”).html(响应);
$(“这里有数据”).fadeIn();
console.log(数据列表);
});
}
}
});
返回false;
});
});
然后在change-loop.php中
<?php
echo $_POST['datalist'];
?>
谢谢您的回复。我将console.log
项放在AJAX调用之前。并将php代码添加到我的change-loop.php中。但是没有回声。我添加了session_start()代码>到HTML(页面顶部,在任何其他内容之前)和change-loop.php,但仍然没有任何内容。有什么想法吗?@Jay oh你把ajax中的数据改成了数据:{datalist:datalist},
?是的,就是这样。没看到那被改成了。非常感谢。谢谢你的回复。我将console.log
项放在AJAX调用之前。并将php代码添加到我的change-loop.php中。但是没有回声。我添加了session_start()代码>到HTML(页面顶部,在任何其他内容之前)和change-loop.php,但仍然没有任何内容。有什么想法吗?@Jay oh你把ajax中的数据改成了数据:{datalist:datalist},
?是的,就是这样。没看到那被改成了。非常感谢。