php - 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);
?>
解决方案
嗨,您在引号中缺少 id (usercommentdiv),
success: function(comment){
$('#usercommentdiv').apprend('<li>' + comment.user_name + ':' + comment.profile_comment + ',' + comment.time_added + '</li>');
}
推荐阅读
- java - 在 Spring-Batch 的上下文中持久存在实体 (jpa) 的问题,该实体是一个带有一些额外字段的连接表
- django - 如何在 Django 中将参数传递给计划的 cron 任务?
- nestjs - NestJs:为什么我们不使用 DTO 来替换所有接口?
- meteor - BigBlueButton 自定义
- angular - CSRF 实施不适用于 OAM
- python - Discord Python 异步事件循环已关闭
- python - 使用 Python 遍历嵌套列表
- php - CakePHP - 在 null 上调用成员函数 allow()
- excel - IF 函数,条件乘法
- protractor - 如何使用量角器/黄瓜/打字稿在测试框架中以无头模式截屏