如何获得HTML网页在一个jQuery Ajax请求的一部分?换句话说如何在Ajax调用过滤网页内容? [英] How to get a part of HTML webpage in a jQuery ajax Request? In other words how to filter the web page contents on an ajax call?

查看:101
本文介绍了如何获得HTML网页在一个jQuery Ajax请求的一部分?换句话说如何在Ajax调用过滤网页内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

谢谢, 迈克

解决方案

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

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);
 }

这篇关于如何获得HTML网页在一个jQuery Ajax请求的一部分?换句话说如何在Ajax调用过滤网页内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆