English 中文(简体)
使用 jQuery 提醒使用.ajax的 HTML 元素
原标题:Alerting HTML elements with .ajax using jQuery

是否有办法提醒所有 HTML 从这个.ajax得到的?

function testq() {    
    var acronyms = ["fubar", "snafu", "gnu"];

    $.each(acronyms, function(index, element) {
        $.ajax({
            url: "https://encrypted.google.com/search?q=" + element,
            dataType: "html",
            success: function(html) {
                var $container = $("#leftnav", html); // look for a specific element in the returned HTML
                jAlert($container);
            }
        });
    });
}​

这只是为了调试。我稍后将修改从.ajax页面获取的信息。

最佳回答

首先,我想提醒大家注意我的要求得到的所有 HTML 。

您只提醒一个特定元素 :

var $container = $("#leftnav", html); // look for a specific element in the returned HTML
jAlert($container);

更改到

jAlert(html);
问题回答

替换 $container 使用 > html :

jAlert(html);

您可以使用 jAlert ($container.html ()) 来获取您 jQuery 对象的html内容, 或者简单 jAlert(html) 来获取全部内容, 但如果您这样做是为了调试, 我建议使用一个合适的控制台, 如火虫, 或铬嵌入控制台, 并从那里调用ajax 来检查返回值, 而不是试图提醒

ưμ㼯A





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!