在javascript中将[object HTMLCollection]转换为字符串 [英] converting a [object HTMLCollection] into string in javascript
问题描述
我尝试使用由 getElementByTagName
从XML文件中提取的数据,并且它返回 HTML集合对象
,但是我需要这些数据来发送REST请求,所以我需要将HTML Collection Object转换为字符串。如何做?
以下是更多信息:
com_zimbra_om .prototype._responseHandler =
函数(响应){
尝试{
sid = response.xml.getElementsByTagName(session_id);
this.login_user();
} catch(e){
this._showErrorMsg(e);
}
使用这个函数我试图得到 session_id
来自REST响应。这里 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);
所以我在这里使用 sid
需要作为字符串。
那么我应该如何将HTML集合对象转换为字符串?
谢谢
$ b有了这些信息,我只能跟着
var objectHTMLCollection = document.getElementsByTagName(div),
string = [] .map.call(objectHTMLCollection,function(node){
return node.textContent || node.innerText ||;
})。join();
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?
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:
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.
So how should I convert HTML Collection Object into string??
Thanks
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("");
这篇关于在javascript中将[object HTMLCollection]转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!