如何获得HTML网页在一个jQuery Ajax请求的一部分?换句话说如何在Ajax调用过滤网页内容?网页、如何获得、内容、如何在

由网友(情绪疯子#)分享简介:我使用的是下面的脚本加载在我的网页的HTML。然而它加载所有的包含在webpage.html装置页面内容(从文档类型在关闭HTML标记)。$(函数(){$阿贾克斯({键入:GET,网址:webpage.html数据类型:HTML,成功:功能(数据){警报(数据);$(机构)HTML(数据);},错误:函数(){警报(错...

我使用的是下面的脚本加载在我的网页的HTML。然而它加载所有的包含在webpage.html装置页面内容(从文档类型在关闭HTML标记)。

  $(函数(){
            $阿贾克斯({
                键入:GET,
                网址:webpage.html
                数据类型:HTML,
                成功:功能(数据){
                    警报(数据);
                    $(机构)HTML(数据);
                },
                错误:函数(){
                    警报(错误);
                }
            })
        });
 

我有超过webpage.html无法控制,我其实只是需要一些div的特别班一个Ajax请求后加载。任何人都可以给我一些想法,我怎么会在一个AJAX调用,对此我无法控制过滤网页内容。

谢谢, 迈克

解决方案

 成功:功能(数据){
     变量超出=;
     $(数据).find(你的选择)。每个(函数(循环项目){
         OUT + = $(项目)的.html();
     });
     数据=输出;
     警报(数据);
     $(机构)HTML(数据);
 }
 

JQuery Ajax

I am using the below script to load the html in my page. However it loads all of the page contents that is included in webpage.html means(from doctype to closing html tag).

$(function() {
            $.ajax({
                type:"GET",
                url:"webpage.html",
                dataType:"html",
                success:function(data) {
                    alert(data);
                    $("body").html(data);
                },
                error:function() {
                    alert("Error");
                }
            })
        });

I have no control over webpage.html, I actually just need a few divs with particular classes to load after an ajax Request. Can anyone give me some Idea as to how would I filter the webpage contents over an ajax Call for which I have no control.

Thanks, Mike

解决方案

 success:function(data) {
     var out = "";
     $(data).find("your selectors").each(function(loop, item){
         out += $(item).html();
     });
     data = out;
     alert(data);
     $("body").html(data);
 }

阅读全文

相关推荐

最新文章