ajax请求后无法从jquery对象获取div内容 [英] Can't get div content from jquery object after ajax request

查看:116
本文介绍了ajax请求后无法从jquery对象获取div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的jquery:

Here is my jquery:

$.ajax({
url: hash,
    success: function(data){
        var thePage = $(data);
        alert(data);
        $('#slider_menu').html($('div#menu_bg', thePage).html());
    }
});

警报(数据)返回以下内容:

The alert(data) returns this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Pharma Mix</title>
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var currentX = 0;
        var currentY = 0;
        var pixelIncrement = 39;
        var currentFrame = 0;
        var currentImage = '';
        $('#rotator').mousemove(function(e){
            currentY = e.clientY - this.offsetTop;
            currentX = e.clientX - this.offsetLeft;
            currentFrame = (parseInt(currentX / pixelIncrement) + 1);
                //$(this).html(currentFrame);
                if(currentFrame < 12)
                {
                currentImage = String(currentFrame) + ".jpg" 
                $(this).css({'backgroundImage':'url("images/' + currentImage + '")'});
                }
        });
     });    
    </script>
</head>

<body>

    <div id="menu_bg">
        <div id="wrapper">       
            <div style="height:30px; background:#009de4"></div>
            <div id="homepage_menu">
                <div style="float:left"><br><a href="#healthcare.php"><img src="images/hcpbutton.jpg" style="margin-right:25px"></a><a href="#pharma.php"><img src="images/pharmabutton.jpg"></a></div>
                <div style="float:right"><br><img src="images/pharmamixlogo.jpg" alt=""></div>  
            </div> <!-- #homepage_menu -->                   
        </div> <!-- #wrapper -->  
    </div> <!-- #menu_bg -->        


    <div id="homepage_bg"> 

        <div id="homepage_wrapper">

            <div style="text-align:center"><img src="images/homepage_heading.jpg" alt=""></div>

            <div id="homepage_leftboxes">
                <div class="homepage_box1">
                    <p class="homepage_boxtext">
                    "Thanks for delivering an outstanding event. Feedback has been excellent all round - in terms of programme, venue, ambiance, technical delivery and the conference team."
                    <br><br>
                    <b>Tracey Guise</b>, BSAC
                    </p>
                </div> <!-- #homepage_box1 -->              
                <div class="homepage_box3">
                    <p class="homepage_boxtext">
                    The whole event ran very well - Debbie did an excellent job of keeping it all running very smoothly indeed.
                    <br><br>
                    <b>Anthony Grosso</b>, UCLH
                    </p>
                </div> <!-- #homepage_box3 -->
            </div> <!-- #homepage_leftboxes -->         

            <div id="rotator" style="width:430px;height:336px; float:left;" class="initalise"></div>

            <div id="homepage_rightboxes">            
                <div class="homepage_box2">
                    <p class="homepage_boxtext">
                    "The understanding and creative thinking that Pharma Mix have demonstrated has provided some genuine and demonstratable return on investment to the Evolution brand."<br><br>
                    <b>Luke Rudman</b>, Evolution Homecare
                    </p>
                </div> <!-- #homepage_box2 -->
                <div class="homepage_box4">
                    <p class="homepage_boxtext">
                    "I would like to thank Debbie & her team for the excellence in the delivery of this superb website & her patience with us."
                    <br><br>
                    Kevin Palmer, Mundipharma
                    </p>                        
                </div> <!-- #homepage_box4 -->

            </div> <!-- #homepage_rightboxes -->  

            <div style="height:170px;"><img src="images/homepage_clients.jpg"></div>

        </div><!-- #homepage_wrapper --> 

    </div><!-- #homepage_bg --> 

    <div style="color:white; text-align:center; padding-top:30px">Contact Us: 28b Priestgate  .  Peterborough  .  PE1 1JA  .  UK   Tel: 01733 554472</div>

</body>
</html> 

但是#menu_bg div不会返回其内容! :(

But the #menu_bg div won't return its content! :(

此方法适用于文档中进一步嵌入的所有div(例如,这将起作用),但我对所请求页面的内容真的没有任何发言权.

This WORKS for any divs embedded further into the document (eg This will work) but I really don't have any say over the content of the page being requested.

有什么想法为什么行不通?还是如何使其工作?

Any ideas why this won't work? Or how to make it work?

谢谢

推荐答案

必须更改返回的代码...没有答案-它必须是错误或类似错误.

Had to change the returned code... there was no answer - it must be a bug, or similar.

这篇关于ajax请求后无法从jquery对象获取div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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