jQuery AJAX加载[重复]


                            
            

                

                    

                        

                             此问题已在此处提供答案</ b>:
                            
                         </ div>
                     </ div>
                 </ div>
                        

                             如何返回异步调用的响应?</ a >
                                
                                     (38个答案)
                                 </ span>
                         </ div>
                
已关闭 6年前</ span>。</ div>
             </ div>
         </ aside>

如何将JQuery AJAX load()函数的返回值保存在变量中?
例如
var temp =“”; </ p>

  $(“#div1”)。load(“ demo_test.txt#p1”);
</ code> </ pre>

因此,我不想将返回值保存在div1中,而是将其保存在变量temp中。</ p>

谢谢</ p>
     </ div>

展开原文

原文

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个回答


load()</ code>只是 $。get </ code>的快捷方式,它也自动插入内容。
如果要将数据存储在变量中而不是直接插入到元素中,则可以使用 $。get </ code>。</ p>

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

展开原文

原文

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');
});


您可以尝试以下方法:</ p>

  $(“#div1”).load(“ demo_test.txt”,function(data){
   var temp = data;
});
</ code> </ pre>
     </ div>

展开原文

原文

You could try something like:

$( "#div1" ).load( "demo_test.txt", function(data) {
  var temp = data;
});


  $(“#div1”).load(“ demo_test.txt”,function(响应,状态,xhr){
      var saved_response =响应;
});
</ code> </ pre>

更多信息,请访问 https://api.jquery.com/load/ </ p>
     </ div>

展开原文

原文

$( "#div1" ).load( "demo_test.txt", function( response, status, xhr ) {
     var saved_response = response;
});

Look more at https://api.jquery.com/load/

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐