脚本加载xhr响应

时间:2014-09-10 16:56:07

标签: javascript php xmlhttprequest load

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

xhr.onreadystatechange = function(e) {
    if(this.readyState === 4) {
        alert(xhr.responseText);
    }
};

xhr.open('POST', 'includes/dodaj-slike.php', true);
xhr.send(formdata);

警告 responseText 是(示例):

<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>

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

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

1 个答案:

答案 0 :(得分:-1)

你可以用

完成
document.head.appendChild(responseText);

正如建议的那样正确

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