xhr响应上的脚本加载


Script load on xhr response

我对responseText有问题。我想从includes/dodaj-like.php(这是echo)加载脚本

xhr.onreadystatechange = function(e) {
    if(this.readyState === 4) {
        alert(xhr.responseText);
    }
};
xhr.open('POST', 'includes/dodaj-slike.php', true);
xhr.send(formdata);

警报响应文本是(示例):

<script type='text/javascript'>
    $('ul li:nth(0)').append('<img src='uploads/cropped_2013-08-12 00.50.37.jpg'/>');
</script>
<script type='text/javascript'>
    $('ul li:nth(1)').append('<img src='uploads/cropped_2013-08-18 12.56.24.jpg'/>');
</script>

我得到了这个,我想以某种方式在响应后立即加载这个脚本。

我的问题是如何以这种方式加载脚本

您可以使用

document.head.appendChild(responseText);

正确的方式将如建议的那样

$("head").append(xhr.responseText);