首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AJAX请求未获取任何信息

AJAX请求未获取任何信息
EN

Stack Overflow用户
提问于 2012-05-04 06:30:10
回答 2查看 52关注 0票数 0

下面是我的PHP文件代码:

代码语言:javascript
复制
<?php
require('config.inc'); //Init DB.

$current_user_id = $_GET['uid']; //Set User ID From AJAX GET.

mysql_query("USE social-network"); //Set MySQL DB.

$userFavs = "SELECT subscribee_id FROM subscribe WHERE subscriber_id = '" . $current_user_id . "'"; //Get people user is subscribed to.

$query="SELECT * FROM posts WHERE (post_owner_id IN ($userFavs) OR post_owner_id = '" . $current_user_id . "') ORDER BY id DESC"; //Select posts by user AND by people user is subscribed to.

$result=mysql_query($query); //Do the query.

$num=mysql_numrows($result); //Get number of rows in query.

$i=0; //Display selected posts.
while ($i < $num) {

$owner_id=mysql_result($result,$i,"post_owner_id");
$content=mysql_result($result,$i,"content");
$date=mysql_result($result,$i,"date");


$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM `social-network`.`users` WHERE id = '" . $owner_id . "'") or die(mysql_error());
$post_firstname=mysql_result($poi_query, 0, "firstname");
$post_lastname=mysql_result($poi_query, 0, "lastname");
$post_profile_picture=mysql_result($poi_query, 0, "profile_picture");
?>

      <div class="post">
        <h1 class="post-title"><a href="profile.php?user=<?php echo $owner_id; ?>"><?php echo $post_firstname; ?> <?php echo $post_lastname; ?></a></h1>
        <p class="content"><?php echo $content; ?></p>
        <p class="details"><?php echo $date; ?></p>

      </div>

      <?php
$i++;
}
?>

下面是我的JS AJAX请求:

代码语言:javascript
复制
function loadPosts()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","PHP/news-feed.php?uid=<?=$current_user_id?>",true);
xmlhttp.send();
document.getElementById("posts").innerHTML=xmlhttp.responseText;
}

在我的页面上,帖子部分什么也没有显示出来。我做错了什么?PHP代码已经过测试,当我直接将它包含在帖子页面中时,它就可以工作了。我正在尝试做的事情:PHP Newsfeed with Reload

EN

回答 2

Stack Overflow用户

发布于 2012-05-04 06:33:19

id为“post”的元素在哪里?我只能看到一个带有post类的div标签

票数 0
EN

Stack Overflow用户

发布于 2012-05-04 06:38:28

ajax的一个错误是假设它是同步的:您期望在发送请求后立即得到结果,但实际上您应该在onreadystatechange事件上附加一个事件处理程序。

如果您没有使用ajax的经验,我建议您使用像jQuery这样的库来为您处理。

除此之外,我也不知道你在哪里调用你的ajax函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10440189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档