为了账号安全,请及时绑定邮箱和手机立即绑定

未使用事件侦听器“this”中的 Javascript jquery 访问全局变量

未使用事件侦听器“this”中的 Javascript jquery 访问全局变量

月关宝盒 2022-01-13 15:46:29
我是初学者。我试图访问 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>     
查看完整描述

1 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

我会说你可能会被“关闭”绊倒。这里有一个外部循环,它发出异步 JavaScript 请求。神奇的是,他们可以使用当时的价值i。但是不能保证在data[]实际执行语句时数组实际上包含该元素。

我在这里看到了各种其他印刷错误问题……result 对比 results等等。非常仔细地检查你的逻辑,并确保你完全理解它应该做什么。


查看完整回答
反对 回复 2022-01-13
  • 1 回答
  • 0 关注
  • 139 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号