首页 > 解决方案 > Jquery获取请求不显示数据

问题描述

好的,我有两页。getprofilecomment.php 和 getprofilecomment.js。获取 getprofilecomment.php 正在运行,但 getprofilecomment.js 由于某种原因无法正常工作。它不显示任何内容。div id 是正确的。这是代码:

$(function()
{
var userId = $(#userid).val();

$.ajax({
  url: "api/getprofilecomment.php",
  method: "GET",
  data: userId,
  cache: false,
  success: function(comment){
       $(#usercommentdiv).apprend('<li>' + comment.user_name + ':' + comment.profile_comment + ',' + comment.time_added + '</li>');
  }
});
});

再次, json_encode 将内容成功回显到页面。

<?php
include ("../db/database.php");
include ("../classes/profilecommentclass.php");

session_start();
$profileCommentHandler = new ProfileComment($db);
$userId = $_GET['userId'];
$profileComment = $profileCommentHandler->getComment($userId);
echo json_encode($profileComment,  JSON_FORCE_OBJECT);
?>

标签: phpjquery

解决方案


嗨,您在引号中缺少 id (usercommentdiv),

success: function(comment){
       $('#usercommentdiv').apprend('<li>' + comment.user_name + ':' + comment.profile_comment + ',' + comment.time_added + '</li>');
  }

推荐阅读