简体   繁体   English

使用Ruby on Rails和Ajax从外部URL获取元标记

[英]Get meta tags from external URL using Ruby on Rails and Ajax

I'm creating a form which contains the fields "URL", "Title" and "Image". 我正在创建一个包含“ URL”,“ Title”和“ Image”字段的表单。 I'd like to update the value of title and image textboxes when user paste a URL in the first field(onkeyup). 当用户在第一个字段(onkeyup)中粘贴URL时,我想更新title和image文本框的值。 These values could come from meta tags. 这些值可能来自meta标签。 How can I do it? 我该怎么做? Thanks. 谢谢。

You could perform an ajax request to a second endpoint within your app, which sends the url that the user has entered. 您可以向应用程序内的第二个端点执行ajax请求 ,该请求将发送用户输入的URL。 That endpoint would use the opengraph gem which extracts the metadata and returns it to the page as json data. 该端点将使用opengraph gem来提取元数据,并将其作为json数据返回到页面。 That data would then be used to populate the other form fields. 然后,该数据将用于填充其他表单字段。

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

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