[英]How to have 2 Ajax Calls for 2 different PHP files?
I'm having 3 php
files, first one is posts.php
,inside this file some PHP
code and here's the javascript
and AJAX
code: 我有3个
php
文件,第一个是posts.php
,在此文件中有一些PHP
代码,这是javascript
和AJAX
代码:
<script type="text/javascript">
$(document).ready(function(){
$("table").on('click','a',function() {
var ID = $(this).attr("id");
$.ajax({
type: 'POST',
cache: false,
url: 'posts_info.php',
data: {id:ID},
success: function(html){
$("#more"+ID).before(html);
alert('this is the info');
}
});
});
$('#content').on('click','.more',function( event){
var ID = $(this).attr("id");
if(ID)
{
$("#loader").show();
$.ajax({
type: 'POST',
url: 'posts_load.php',
data: {id:ID},
cache: false,
success: function(html){
$("#loader").hide();
$("#more"+ID).before(html);
$("#more"+ID).remove();
alert('this is moreee posts');
}
});
}
});
});
</script>
The first ajax
call happends when the user clicks on an image.The second when the user clicks on a hyperlink "more". 当用户单击图像时,将发生第一个
ajax
调用。当用户单击超链接“更多”时,将发生第二个ajax
调用。 Each of the posts.info
file and posts_load
file loads different content When the user clicks on the image the content from the posts_info
is displayed successfully.Also, when the user then clicks on the more link the content of the posts_load
is displayed successfully.The problem is when the user clicks on more , posts_load.php
is loaded.However after that when the user clicks on the image , nothing is displayed from " posts_info.php
". 每个
posts.info
文件和posts_load
文件加载不同的内容当用户单击图像时, posts_info
的内容将成功显示。此外,当用户单击more链接时, posts_load
的内容将成功显示。问题是,当用户单击更多时,将posts_load.php
但是,此后,当用户单击图像时,“ posts_info.php
” posts_info.php
不显示任何内容。 The call is made successfully till the alert part however nothing is displayed.Any help? 呼叫成功完成,直到警报部分,但是什么也没有显示。有帮助吗?
problem is when the user clicks on more ,posts_load.php is loaded.However after that when the user clicks on the image , nothing is displayed from "posts_info.php".The call is made successfully till the alert part however nothing is displayed
问题是,当用户单击更多时,将加载posts_load.php。但是,此后,当用户单击图像时,“ posts_info.php”中将不显示任何内容。调用成功,直到警报部分,但不显示任何内容
As i can see your code may be problem is this: 如我所见,您的代码可能是这个问题:
When you click on Image, In second ajax call you are removing element: 当您单击Image时,在第二个ajax调用中,您正在删除元素:
$("#more"+ID).remove();
Then you are adding when click on a
然后你在添加时,点击
a
$("#more"+ID).before(html);
Its not adding response content because element is already removed from DOM . 它没有添加响应内容,因为element已从DOM中删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.