Javascript Error Analysis

Source: Internet
Author: User

Analysis of "unended string constants"

For JavaScript debugging, skip "uncompleted string constants". Detailed analysis: Action sets a data request. setattribute ("sendokmsg", sendokmsg); To Display alert ("<%= (string) request in JavaScript. getattribute ("sendokmsg") %> "), the title is displayed. However, <% SYSTEM. Out. println (string) request. getattribute ("sendokmsg"); %> can be displayed on the console.
Why:
 
Cause of "unended String constant" error:
1. When Javascript is referenced, the character languages used are inconsistent.
For example, <SCRIPT type = "text/JavaScript" src = "XXX. JS "charset =" UTF-8 ">. xxx. JS file is used inside the gb2312 format, calling outside is used UTF-8, so some special characters inside the file because of inconsistent formats, garbled, this cause.

2. When JavaScript outputs HTML characters, the front and back labels do not match.
This is common. when outputting a string, single quotation marks (') or double quotation marks (") are not paired, or. when writing (), the single quotation mark (') or double quotation mark (") is not correctly output (")

3. html markup language or line break in the Parameter
What I encountered today is this situation. because the data obtained is passed to a function as a parameter, the data contains a line break, causing this error. for example, it is normal to use only a single row of data during the test. This error is not reported ,. this error occurs when multiple rows of data are used during the test and the carriage return link is used for line feed. because it contains line breaks
 
For the 3rd cases, my solution is:
1. Instead of directly passing the data as parameters, the data is first assigned to a hidden text. You only need to read the content of the text in the function to be called.
 
2. Transfer the information without special symbols and resolve the group to Js.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.