简体   繁体   English

使用jQuery从另一个页面加载元数据

[英]Loading meta data from another page using jQuery

I'm trying to use the jQuery load method to grab some meta data from another page and insert it in a <div> , but I'm a little stuck. 我正在尝试使用jQuery load方法从另一个页面中获取一些元数据并将其插入<div> ,但是我有点卡住了。

I'm using something similar on the other page in which I grab the location meta data and put it in a <p> . 我在另一页上使用了类似的内容,在其中我获取了位置元数据并将其放在<p> To do this I use the following: 为此,我使用以下命令:

<script>
  var locationMeta = $('meta[property="og:locality"]').attr('content');
  $( 'p.locationMeta' ).text( locationMeta );
</script>

For this new task, I need to use something like: 对于这项新任务,我需要使用以下方法:

$( "#mydiv" ).load( "href #target" );

The #target in this case needs to be meta[property="og:locality"] . 在这种情况下, #target必须是meta [property =“ og:locality”]

nb I've tried to load the p.locationMeta as the target. nb我试图加载p.locationMeta作为目标。 It loads but it's empty. 它已加载,但为空。

I think you're getting load wrong. 我认为您加载错误。 if you do load(url), url have to be a valid url, a path to the page you're trying to load. 如果您要加载(url),则url必须是有效的url,即您要加载的页面的路径。 you can do load(url selector) like this: 您可以像这样进行加载(URL选择器):

$( "#mydiv" ).load( "test.html meta[property='og:locality']" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM