?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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题