我尝试从我的html字符串中的div中获取值时出现问题。也许这里有人可能会为我找到问题。从jquery和ajax的html字符串中获取div的值
我试过很多不同的方法来取出数据。对别人有效的解决方案根本不适用于我。所以,我觉得我做的事情严重错误
$(document).ready(function() {
var id = 1;
function updateMsg() {
$.ajax({
url: "/opt/history/update?current=" + 1,
cache: false,
success: function (html) {
id = $(html).find('#last').html();
console.log('ID: ' + id);
$("#result").html(html);
}
});
setTimeout(updateMsg, 5000);
}
updateMsg();
});
这是div怎么看起来像
<div id="last" style="display: none;">2</div>
有这个div之前一串HTML代码。这个div总是在html字符串的底部。
更新:事情是。我需要在这个html字符串中传输一个id的值,但不能直观地显示它。如果你有更好的办法,我应该看看。
成功
<tr>
<td>2014-07-08 14:35:47.456</td>
<td>123</td><td>321</td>
<td>Has data</td>
<td><a data-toggle="modal" data-request="2014-07-08 14:35:47.456" data-mobile="123" data-check="321" data-log="Has latest update" data-context="Context" data-historyid="28" title="info" class="open-logInfo btn btn-default" href="#logInfo">
<i class="icon-info-sign icon-black"></i> Info </a>
</td>
</tr>
<div id="last" style="display: none;">28</div>
'我有一个问题,当我尝试从我的html字符串中的一个div中获取值。“什么问题? – Nivedita
当我尝试console.log的id值。对于我试过的所有内容,它是空的或未定义的 –
您可以在成功回调中提供'console.log(html)'输出。 – PeterKA