我想使用 ajax 将字符串发布到 html 文件。
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support Ajax HTTP");
return;
}
xmlhttp.onreadystatechange=getOutput;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
在 url 中,我在另一个文件中发送了我想要的参数。它还包含一个带有 html 标签的字符串,如下所示
<table id='detReportTable' style='color:#333333;font-family:sans-serif;width:97%;margin-left:10px;'><tbody><tr><td colspan='2' style='text-align:center;'><div style='font-size: 19px;font-weight: bold;' id='score_cont'></div></td></tr></tbody></table>
我将这个字符串作为参数发送,但它没有得到这个参数,没有 html 标签的其他参数将发送,例如:foo=sample
。它告诉我一个错误。我可以发送这个 html 字符串吗?或者我的方式有误,请提出任何想法。
提前致谢。
最佳答案
为什么不正常传递所有这些信息呢?为什么需要包含 html 标签??
您的代码因等号 (=) 而中断。您可以用 ~ 替换所有等号,然后完整参数将被传递,在另一页上,您可以通过将 ~ 替换回 =
来修复它例子:
var parameters = " < table id='........ >";
while( parameters.indexOf('=')>=0 ){
parameters = parameters.replace('=','~');
}
你还需要替换#
关于javascript - 在 javascript 中发布一个包含 html 标签的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882333/