使用包含图像标记的内容设置元素的html源

时间:2012-06-07 12:05:39

标签: javascript mootools

我正在使用Mootools History plugin更新页面内容,而不需要重新加载页面。

除了Mootools在正在注入的内容中生成404错误(在控制台中可见)时,一切正常。

通过Request.HTML调用收集和设置内容,如下所示(简化演示):

var request = new Request.JSON({
    onSuccess: function(responseJSON, responseText) {
        html = JSON.decode(responseJSON);
        $('zone').set('html', html['text']);
    }
});

正在正确设置内容,但.set('html', content)似乎通过重写图片的src属性来生成404错误。

网址看起来像这样:

http://example.com/%22//files//images//ImageName.jpg/%22

虽然页面源显示为:

/files/images/ImageName.jpg

404错误是指Mootools Core中的第334行,但我看不出那会导致问题的地方。

1 个答案:

答案 0 :(得分:1)

解决方案是使用Request.JSON而不是Request.HTML并直接访问JSON对象而不是先解码它。

var request = new Request.JSON({
    onSuccess: function(responseJSON, responseText) {
        $('zone').set('html', responseJSON.text);
    }
});

部分由@DimitarChristoff

建议
相关问题