?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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿