相关疑难解决方法(0)

使用jquery解析html字符串

我有一个来自Ajax加载源的HTML字符串.在将HTML放入文档之前,我想从此字符串中的对象(图像)获取一些属性.

我有类似的东西:

$.ajax({  
        url: uri+'?js',  
        success: function(data) { 
            var htmlCode = $(data).html();  

            $('#otherObject').html(data);
        }  
    });
Run Code Online (Sandbox Code Playgroud)

如何src从此HTML字符串中获取属性(例如)?

jquery

60
推荐指数
1
解决办法
10万
查看次数

简单的jQuery ajax示例没有在返回的HTML中查找元素

我正在尝试学习jQuery的ajax函数.我有它的工作,但jQuery没有在返回的HTML DOM中找到元素.在与jquery相同的文件夹中,运行此页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>runthis</title>

    <script type="text/javascript" language="javascript" src="jquery-1.3.2.min.js"></script>

    <script tyle="text/javascript">
    $(document).ready(function(){
        $('input').click(function(){
            $.ajax({
                type : "GET",
                url : 'ajaxtest-load.html',
                dataType : "html",
                success: function(data) {

                alert( data ); // shows whole dom

                alert( $(data).find('#wrapper').html() ); // returns null

                },
                error : function() {
                    alert("Sorry, The requested property could not be found.");
                }
            });
        });
    });
    </script

</head>
<body>
    <input type="button" value="load" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

加载此页面"ajaxtest-load.html":

<!DOCTYPE html PUBLIC …
Run Code Online (Sandbox Code Playgroud)

ajax jquery parsing dom

11
推荐指数
2
解决办法
4万
查看次数

jquery ajax解析响应文本

好吧,这真的让我感到很沮丧,因为我之前已经完成了这一百次,而这次它没有用.所以我知道我做错了什么,我只是想不出来.

我正在使用jQuery .get例程从另一个文件加载html.我不想使用.load(),因为它总是替换我正在加载内容的元素的子元素.

这是我的.get请求:

$(document).ready(function() {
    $.get('info.html', {}, function(html) {
        // debug code
        console.log($(html).find('ul').html());
        // end debug code
    });
});
Run Code Online (Sandbox Code Playgroud)

文件'info.html'是一个带有正确doctype的标准xhtml文件,正文中唯一的东西是我需要访问的一系列ul.出于某种原因,find函数给我一个空值.

在firebug中,GET请求显示正确的RESPONSE文本以及何时运行

console.log(html);
Run Code Online (Sandbox Code Playgroud)

而不是当前的console.log行,我将整个info.html作为输出,就像我期望的那样.

有任何想法吗?

html javascript ajax jquery

9
推荐指数
3
解决办法
4万
查看次数

如何检索资源的og/meta属性?

我正在制作一个在用户的Twitter上检索推文的应用程序.

这些Feed包含指向外部资源的链接,例如Artciles,网页或YouTube视频.

我在Twitter API中提供了这些Feed的JSON,但是没有包含og:内容的属性.而且我想抓住它们并显示到我的网站上.

比如StackOverflow的这个问题:

<meta name="og:type" content="website" />
<meta name="og:image" content="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6"/>
<meta name="og:title" content="How can I check classes that ends with?" />
<meta name="og:description" content="I have some elements such as:
    &amp;lt;div class=&quot;button 17-facebook-dashboard-check&quot;&amp;gt;Elem1&amp;lt;div&amp;gt;
    &amp;lt;div class=&quot;button 18-google-dashboard-check&quot;&amp;gt;Elem2&amp;lt;div&amp;gt;
    &amp;lt;div class=&quot;button " />
<meta name="og:url" content="https://stackoverflow.com/questions/19001883/how-can-i-check-classes-that-ends-with"/>
Run Code Online (Sandbox Code Playgroud)

我想在每条推文上捕获每个共享资源的信息.所以我觉得我会,每个鸣叫(这对我来说是一个盒子)做一个Ajax请求的客户端,下载HTML和解析它,检索og:title,og:description,og:typeog:image.

这是最好的方法吗?什么是在Javascript/Jquery中解析这些数据?

html javascript meta jquery opengraph

8
推荐指数
2
解决办法
1万
查看次数

通过jQuery获取META描述

假设我做一个简单的AJAX请求(在jQuery中)就像 geturl.php?url=http://google.com

并且geturl.php是这样的:

<?php
    if($_GET['url'])
    {
        $url=$_GET['url'];
        echo file_get_contents($url);
    }
?>
Run Code Online (Sandbox Code Playgroud)

简单吧?

我如何从jQuery中返回的(非常长的)字符串中获取META描述?

这是我到目前为止所拥有的.是的,我知道,desc是错的.

$.get("geturl.php?url="+url,function(response)
{
    // Loading <title></title>data
    var title=(/<title>(.*?)<\/title>/m).exec(response)[1];
    var desc = $("meta[name=description]").val();
    $("#linkbox").html("<div><b>"+title+"</b><br/>"+url+"<br />Desc: " + desc)
});
Run Code Online (Sandbox Code Playgroud)

php jquery

3
推荐指数
1
解决办法
7679
查看次数

什么正则表达式会匹配这些数据?

我在XHTML文档中有以下内容:

<script type="text/javascript" id="JSBALLOONS">
    function() {
        this.init = function() {
            this.wAPI = new widgetAPI('__BALLOONS__');
            this.getRssFeed();
        };
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我正在尝试选择两个脚本标记之间的所有内容.该id会一直JSBALLOONS是否有帮助.我知道如何选择包括脚本标签,但我不知道如何选择除脚本标签之外的内容.正则表达式的结果应该是:

    function() {
        this.init = function() {
            this.wAPI = new widgetAPI('__BALLOONS__');
            this.getRssFeed();
        };
    }
Run Code Online (Sandbox Code Playgroud)

javascript regex xhtml parsing html-parsing

0
推荐指数
1
解决办法
575
查看次数

标签 统计

jquery ×5

javascript ×3

ajax ×2

html ×2

parsing ×2

dom ×1

html-parsing ×1

meta ×1

opengraph ×1

php ×1

regex ×1

xhtml ×1