Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax获取返回未定义的HTML';src&x27;用于图像_Jquery_Ajax_Html Table_Src_Targeting - Fatal编程技术网

Jquery Ajax获取返回未定义的HTML';src&x27;用于图像

Jquery Ajax获取返回未定义的HTML';src&x27;用于图像,jquery,ajax,html-table,src,targeting,Jquery,Ajax,Html Table,Src,Targeting,我以前做过这方面的工作,瞄准div没有问题,但这次我瞄准的是隐藏在一张表中的图像,这张表在intranet站点上已经存在很长时间了。我最终找到了它的代码,并在名为$('.targetTable')的表中添加了一个类名。现在,我正试图从表中提取某些元素,以便在新页面的div中显示。下面是从表中提取HTML的代码: $(document).ready(function(){ $mission = $('#targetDiv'); $.ajax({ url: "http://example.c

我以前做过这方面的工作,瞄准div没有问题,但这次我瞄准的是隐藏在一张表中的图像,这张表在intranet站点上已经存在很长时间了。我最终找到了它的代码,并在名为
$('.targetTable')
的表中添加了一个类名。现在,我正试图从表中提取某些元素,以便在新页面的div中显示。下面是从表中提取HTML的代码:

$(document).ready(function(){

$mission = $('#targetDiv');

$.ajax({
  url: "http://example.com/values/values.cfm?val=commitment",
  cache: false
}).done(function( html ) {
    $div = $('table.targetTable', html);

    $img = $div.children('tr:eq(3)').children('td').find('img').attr('src');

    $mission.append('<img src="'+$img+'" />');

});



});
$(文档).ready(函数(){
$mission=$('targetDiv');
$.ajax({
url:“http://example.com/values/values.cfm?val=commitment",
缓存:false
}).done(函数(html){
$div=$('table.targetTable',html);
$img=$div.children('tr:eq(3)')。children('td')。find('img')。attr('src');
$mission.append(“”);
});
});
以下是通过AJAX调用提取的表:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>commitment</title>
</head>
<body>


<table border="0" style="border: 1px solid gray;" cellspacing="0" class="targetTable">
    <tr style="background-color: #FFDDBB;">
        <td align="center" style="padding: 8px;">

            <img src="../mp_images/values/commitment_med.jpg" width="600" height="439">
        </td>
    </tr>

    <tr style="background-color: #FFDDBB;"> 
        <td valign="top" style="padding: 8px;">     
                <div style="text-align:center; letter-spacing: 4px; font-size: 140%; font-weight: bold; margin-bottom: 30px;">COMMITMENT</div>

                <div style="font-family:Georgia, 'Times New Roman', Times, serif; font-size: 100%">
                We recognize Commitment as a fundamental cornerstone underpinning our everyday activities.  Our commitment is a steadfast devotion to our people, our licensees, and to the public to responsibly carry out the mission of the agency, unwavering from the highest standards of safety, excellence, and professionalism.
                </div>
        </td>

    </tr>

    <tr style="background-color: #FFDDBB;">
        <td style="border-bottom: 1px solid gray;">&nbsp;

        </td>
    </tr>


    <tr bgcolor="white">
        <td align="center" colspan="3" style="padding: 8px;">
            <a href="../values/values.cfm?val=Commitment" ><img src="../mp_images/values/commitment_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Cooperation"><img src="../mp_images/values/cooperation_small.jpg"  border="0" /></a>
            <a href="../values/values.cfm?val=Excellence"><img src="../mp_images/values/excellence_small.jpg"  border="0" /></a>
            <a href="../values/values.cfm?val=Integrity"><img src="../mp_images/values/integrity_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Openness"><img src="../mp_images/values/openness_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Respect"><img src="../mp_images/values/respect_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Service"><img src="../mp_images/values/service_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Mission"><img src="../mp_images/values/Mission_small.jpg" border="0" /></a>
            <a href="../values/values.cfm?val=Vision"><img src="../mp_images/values/Vision_small.jpg" border="0" /></a>
        </td>
</tr>


</table>
</body>
</html>

承诺
承诺
我们认识到承诺是我们日常活动的基础。我们的承诺是坚定不移地致力于我们的员工、我们的许可证持有人和公众,以负责任的方式履行机构的使命,毫不动摇地遵循安全、卓越和专业的最高标准。

现在,每次我以img src为目标时,它都返回为未定义。我的目标是错误的还是像doctype或CFM兼容性之类的东西?另外,由于某种原因,我不知道Chrome会抛出错误。它告诉我,我的AJAX已经将HTML中的所有相对路径转换为绝对路径,但绝对路径指向我的页面,而不是旧页面和图像位置。如果有人能猜出这个问题,我会把你指到我之前问过这个问题的页面上,你会得到一个双重的复选标记

表是body的直接子元素,当body被移除时(它将是),表将成为顶级元素。改变

$div = $('table.targetTable', html);

为避免其他问题,请使用:

$div = $($.parseHTML(html)).filter('table.targetTable');

表是body的直接子元素,当body被移除时(它将被移除),表将成为顶级元素。改变

$div = $('table.targetTable', html);

为避免其他问题,请使用:

$div = $($.parseHTML(html)).filter('table.targetTable');

您还应该在某个地方声明这些变量,而不是让它们进入全局范围,适当地命名它们也是一个好主意。映像源仍然返回为未定义。$img变量返回为“未定义”@DJERock执行正常调试。
$div
是否包含该表?$img=。。。选择器选择正确的表行?第二部分是否选择了正确的td?第三部分是否选择了正确的图像?@DJERock您可以为此感谢您的浏览器,使html成为有效的全部::p您还应该在某个地方声明这些变量,而不是让它们进入全局范围,适当地命名它们也是一个好主意。图像源仍然返回为未定义。$img变量返回为'undefined'@DJERock do normal debug。
$div
是否包含该表?$img=。。。选择器选择正确的表行?第二部分是否选择了正确的td?第三部分是否选择了正确的图像?@DJERock您可以为此感谢您的浏览器,使html成为有效的全部::p在您的html中没有
targetTable
类。对不起,现在已经存在了。我更改了一些内容,以便更好地理解我要查找的内容。。。顺便说一句,这是传入的HTML而不是我的HTML。我的HTML是在append()标记中生成的。您的HTML中没有
targetTable
类。很抱歉,它现在在那里。我更改了一些内容,以便更好地理解我要找的内容。。。顺便说一句,这是传入的HTML而不是我的HTML。我的HTML是在append()标记中生成的