JavaScript error - unterminated string constant

Today the value of a background processing request pass in the js, originally for the easy way, using an EL expression directly in the js, one successful, the other is always being given: "unterminated string constant"! ! !

Finally I discovered that the error of EL expressions pass past values ​​There is a Chinese full stop, leading to always wrap .........

function initpage(){

 var str1 = "${periodTypeValue}";

 var str2 = "${premiumValue}";

 if(str1 != "" ||str2 != ""){

     document.getElementById("showDesc").style.display = "";

     document.getElementById("periodDesc").innerHTML = str1;

     document.getElementById("premiumDesc").innerHTML = str2;

 }

}


<body onload="initpage();">

     <html:form action="/product?method=saveEpolicy" method="post" >

          <table width="90%" height="50%" border="0" cellpadding="0"  class="CContent" cellspacing="0" align="center">

             <col width="20%">

             <col width="35%">

             <col width="15%">

             <col width="30%">

               .........

               <tr style="display: none;" id="showDesc">

                <td>

                       &nbsp;&nbsp;

                </td>

                <Td style = "text-align: left; vertical-align: top;"> <- align = "left" valign = "top" left two ways, the alignment! ->

                      <div id="periodDesc">

                      </div>

                </td>

                <td>

                    &nbsp;&nbsp;

               </td>

               <td style="text-align: left; vertical-align: top;" >

                    <div id="premiumDesc">

                   </div>

              </td>

            </tr>

          </table>

</html:form>

</body>

=============================================

Finally, upon inspection, I see that other users have encountered, there is a hidden form fields to solve, namely: the data are not directly passed as parameters, but the first of its assignment within a hidden text, need to call just read the text function in the contents of the can.


<html:hidden property="premiumValue" styleId="premiumValue" value="${premiumValue}"/>

<html:hidden property="periodTypeValue" styleId="periodTypeValue" value="${periodTypeValue}"/>


Action in the background surprised to discover that pass over a null value, that he should not null thus displayed, but ""


var str1 = document.getElementById("periodTypeValue").value;

 var str2 = document.getElementById("premiumValue").value;



----------------

When 1.JAVASCRIPT reference character language is inconsistent. 

For example:. <Script type = "text / javascript" src = "xxx.js" charset = "UTF-8"> xxx.js GB2312 internal file format is used, the outside call using UTF-8, so the file because the internal part of the special character formatting inconsistencies, garbled, causing this reason.


When 2.JAVASCRIPT output HTML characters before and after markers do not match. 

This more common, often in the output string, appears single quote ( ') or double quotes ( ") does not match, or when document.write () is not correctly output single quotation marks (') or double quotes ( ")


HTML markup language occurs within or line breaks 3. Parameter 

I have encountered this is the case today, because I get the data passed to a function as a parameter, the results of this data contains line breaks, resulting in this error. 

Such as: general test use only a single line of data is normal, the error does not occur. 

When tested using multiple rows of data, using a carriage return linefeed chain, to travel this error because it contains a newline


For the third case, my solution is: do not direct the data passed as parameters, but the first of its assignment within a hidden text function needs to be called in just to read the contents of the text that is can. 


Guess you like

Origin blog.51cto.com/14028890/2400272