下面的函数需要在脚本标记内动态添加,脚本标记也是动态生成的。
var targetFunction=function(){
var sOut='<?xml version="1.0"?>\n';
sOut+='<Logon username="" password="" appversion="1.0">\n';
sOut+='\n</Logon>'
document.getElementById("KXML").value=sOut;
console.log(document.getElementById("KXML").value);
var httpReq = createXMLHttpRequest();
httpReq.open("POST", 'http://my-url', true);
httpReq.setRequestHeader("Content-type","application/xml");
httpReq.setRequestHeader('Accept', 'application/xml');
httpReq.setRequestHeader('X-REST-API', true);
httpReq.onreadystatechange = function() {
if (httpReq.readyState == 4 && httpReq.status == 200) {
document.getElementById('upload_target').innerHTML="";
var serverResponse = httpReq.responseText;
document.getElementById("upload_target").contentWindow.document.body.innerHTML=httpReq.responseText;;
}
}
httpReq.send(document.getElementById("XML").value);
}
此功能将动态添加到iframe中。要做到这一点,我需要它将其转换为字符串。
我尝试将其转换为字符串
alert(eval(targetFunction.toString()));
我无法这样做。感谢任何帮助。
答案 0 :(得分:0)
您是否尝试过使用String()函数?
在此处查看更多内容:http://www.w3schools.com/jsref/jsref_string.asp
编辑:
你试过删除eval吗?
alert(targetFunction.toString());