我有一些问题。jQuery如何从html中获取正文内容
我有一个ajax请求发送出去做数据库更新。然后返回响应,看起来像:
...
...
</head>
<body class="contentpane">
{"id":"27","votes":14,"sum":45,"avg":"3.2"}
</body>
</html>
我怎样才能得到身体级“的contentPane”的内容,然后将其转换为一个JSON对象?
我的要求的功能是这样的:
jQuery.post("index.php?option=com_ttvideo&task=savevote&tmpl=component", {rate: value, id: <?php echo $this->video->id; ?> }, function(html)
{
// get contents of "contentpane" from response html
// convert to JSON object e.g.
// var rating = jQuery.parseJSON(content_of_body);
// is the above JSON parse correct?
// Select stars to match "Average" value
ui.select(Math.round(rating.avg));
// Update other text controls...
jQuery("#avg").text(rating.avg);
jQuery("#votes").text(rating.votes);
// Show Stars
jQuery("#loader").hide();
jQuery("#rat").show();
});
这是我在的Joomla发展的组成部分,以保持的Joomla框架,它需要运行通过组件MVC框架的响应中的PHP函数 - 退的这它是返回所有的HTML以及,啧啧:( – Martin 2010-10-21 15:17:31
我试图通过这一步一次,1.使用var rating = jQuery(“body”,html ).text();但是这个返回空白,用.html()替换为null。 – Martin 2010-10-21 15:24:04
@Martin:我无法想象有没有办法解决这个问题,但我不知道Joomla。这里。 – SLaks 2010-10-21 15:24:39