简体   繁体   English

发布包含javascript中html标记的字符串

[英]Post a string contains html tags in javascript

I want post a string to html file using ajax. 我想使用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();
}

In the url I sent the parameters what i want in the another file. 在url中,我发送了我想要在另一个文件中的参数。 It also contains a string with html tags like this 它还包含一个带有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>

I sent this string as parameter but it does not get this parameter other parameters without having html tags will send eg: foo=sample . 我将此字符串作为参数发送,但没有html标记将无法发送该参数,其他参数将发送例如: foo=sample It shows me a error. 它显示了一个错误。 Can i send this html string or my way is wrong please suggest any idea. 我可以发送此html字符串,还是我的方法有误,请提出任何建议。

Thanks in Advance. 提前致谢。

why not just pass all that info normally? 为什么不正常传递所有这些信息? Why do you need to include the html tags?? 为什么需要包括html标签?

Your codes breaking because of the equals(=). 您的代码由于equals(=)而中断。 You could replace all equals with ~, then the full parameter will get passed, and on the other page u can fix it by replacing ~ back to = 您可以将所有等号替换为〜,然后将传递完整参数,在另一页上,您可以通过将〜替换为=来修复它。

example: 例:

var parameters = " < table id='........ >"; var parameters =“ <表ID ='........>”;

while( parameters.indexOf('=')>=0 ){ while(parameters.indexOf('=')> = 0){

parameters = parameters.replace('=','~'); 参数= parameters.replace('=','〜');

} }

you'll also need to replace # 您还需要替换#

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

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