在javascript中将[object HTMLCollection]转换为字符串

时间:2022-10-24 21:29:42

I am trying to use data extracted from a XML file by getElementByTagName and it returns HTML Collection Object but I need this data for a sending a REST request so I need to get the HTML Collection Object to be converted into a string. How can it be done?

我试图通过getElementByTagName使用从XML文件中提取的数据,并返回HTML Collection Object但我需要这些数据来发送REST请求,所以我需要将HTML Collection Object转换为字符串。如何做呢?

Here's more information:

这里有更多信息:

com_zimbra_om.prototype._responseHandler=
        function(response){
                try{
                    sid = response.xml.getElementsByTagName("session_id");
                    this.login_user();
                    }catch(e){
                            this._showErrorMsg(e);
                            }

Using this function I am trying to get the session_id from a REST response. Here sid (global variable) is the HTML Collection Object. Now when I try to use this in the next function:

使用此函数我试图从REST响应中获取session_id。这里sid(全局变量)是HTML集合对象。现在当我尝试在下一个函数中使用它时:

com_zimbra_om.prototype.login_user = function(){
var url = selected_server + 'services/UserService/loginUser?SID=' +
                                    sid + '&username='+
                                    selected_username +
                                    '&userpass=' + 
                                    selected_password;
                var request_url = ZmZimletBase.PROXY + AjxStringUtil.urlComponentEncode(url);

So here I am using sid which I need as a string.

所以我在这里使用sid作为字符串。

So how should I convert HTML Collection Object into string??

那么我应该如何将HTML Collection Object转换为字符串?

Thanks

1 个解决方案

#1


9  

With this information I can only go with

有了这些信息,我只能参加

var objectHTMLCollection = document.getElementsByTagName("div"),
    string = [].map.call( objectHTMLCollection, function(node){
        return node.textContent || node.innerText || "";
    }).join("");

#1


9  

With this information I can only go with

有了这些信息,我只能参加

var objectHTMLCollection = document.getElementsByTagName("div"),
    string = [].map.call( objectHTMLCollection, function(node){
        return node.textContent || node.innerText || "";
    }).join("");