繁体   English   中英

怎么获得<p>来自 XMLHttpRequest 响应的标记值并在 html 中设置

[英]How to get <p> tag value from XMLHttpRequest response and set in html

我正在尝试使用XMLHttpRequest上传文件,如果出现错误,我会收到整个错误div作为响应。 从那个div ,我希望段落内的文本(文件为空。请提供逗号分隔的 taskids。)标签在 HTML 页面中设置。 谈论代码中的错误代码 409。

要求

var xhr = new XMLHttpRequest();       
var url = '/uiris/actions/'+$("#actionName").val()+'/do?time=' + new Date().getTime()+'&subaction=fileupdate';
xhr.open("POST",url, true);
xhr.send(formdata);
xhr.onload = function(e) {

    if (this.status == 200) {
        refreshView();
    } else {
        if (this.status === 409) {
            $('#action').html(this.responseText);  
        } else if (this.status === 401) {
            window.location = "/xyz/";
        } else if (this.status === 422) {
             alert("Unable to perfom task");
             refreshView();
        } else {
            alert("Unable to connect to application");
        }
        refreshView();
    }
}; 

回复:

    <div id="errorDiv" class="margin-top-10-px">
    <h2>Error</h2>
    <p>File is empty.Please provide comma seperated taskids.</p>
</div>

你可以简单地 jQuery 化它并find你想要的text()

$(this.responseText).find("p").text();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM