Get another page's content in a variable with ajax

后端 未结 1 651
终归单人心
终归单人心 2021-01-01 04:23

Is there a way to set a javascript variable as the content of another HTML page?

I tried:

var X = $(http://www.website.com/home).html()

相关标签:
1条回答
  • 2021-01-01 04:47

    It sounds like you're looking for this:

    $.get('otherPage.html').then(function(responseData) {
      //responseData is the contents of the other page. Do whatever you want with it.
      $('#someElem').append(responseData);
    });
    

    Live demo (click).

    $.get() is a shorthand method for jQuery's $.ajax(). http://api.jquery.com/jquery.ajax/

    0 讨论(0)
提交回复
热议问题