我是初学者。我试图访问 jquery 事件列表器中的对象,但得到未定义或类型错误。我尝试了几种方法尝试以这种方式发送对象 {results: result} 但它不起作用,给了我未定义的错误。我找不到适合我的答案。提前致谢
jquery 整个代码
$(document).ready(function() {
//var $addhere = $("#addhere");
$.ajax({
type: "GET",
url: "/newsfeed/retrieve",
//datatype: "JSON",
success: function(datas){
//console.log(data);
// Check the length of success data.data
const data = datas;
var datalength = Object.keys(data.data).length;
// Calling the result function
var count = 0;
result(data, datalength);
reactions(data, datalength, count);
}
});
function result(result, datalength){
// Values are here im result
console.log(result);
var myPostHtml = '';
// Values in the first place of object array
//console.log(result.data[0].uploads);
for(i=0;i<datalength;i++)
{
//if(result.data[i].uploads.attr("src", "No files uploaded")){
//$("img").hide();
//}
myPostHtml += `<img src="${result.data[i].uploads}" id="contentAreaHomePageTweetPhoto" alt="post-image" class="img-responsive post-image" />
<div class="post-container">
<img src="${result.data[i].uploads}" id="" alt="user" class="profile-photo-md pull-left" />
<div class="post-detail">
<div class="user-info">
<h5><a href="/timeline" id="" class="profile-link">${result.data[i].username}</a> <!--<span class="following">following</span>--></h5>
<p class="text-muted"id="contentAreaHomePageTime">${result.data[i].createdAt}</p>
</div>
HUWWW
相关分类