使用ajax在变量中获取另一个页面的内容
有没有办法将javascript变量设置为另一个HTML页面的内容?
我试过了:
var X = $(http://www.website.com/home).html()
但它没有返回任何东西……即使它解释了这个想法……所以……有人能告诉我怎么做吗? 也是该网站中某个id
或class
的内容,例如:
var X=$(http://www.website.com/home "#id").html()
这对我很有帮助,在此先感谢!
听起来你正在寻找这个:
$.get('otherPage.html').then(function(responseData) { //responseData is the contents of the other page. Do whatever you want with it. $('#someElem').append(responseData); });
现场演示(点击)。
$.get()
是jQuery的$.ajax()
的简写方法。 http://api.jquery.com/jquery.ajax/