?yb? 2014-03-29 21:39 采纳率: 100%
浏览 115

jQuery AJAX加载[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
                            <span class="question-originals-answer-count">
                                (38 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2014-03-29 23:10:45Z" class="relativetime">6 years ago</span>.</div>
        </div>
    </aside>

How can I save the return of the JQuery AJAX load() function in a variable? For example var temp="";

$("#div1").load("demo_test.txt #p1");

So instead of saving the return in div1, I want to save it in the variable temp.

Thank you

</div>
  • 写回答

3条回答 默认 最新

  • weixin_33724046 2014-03-29 21:44
    关注

    load() is just a shortcut for $.get that automagically inserts the content as well. You can use $.get instead if you want to store the data in a variable instead of directly inserting to an element

    $.get('demo_test.txt', function(data) {
        var temp = $('<div />', {html : data}).find('#p1');
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?