Error message garbled by using JS in PHP

Source: Internet
Author: User
: This article describes how to use JS to pop up error codes in PHP. For more information about PHP tutorials, see. Problem Description: submit data from the page to the background (non-Ajax submission). If an error occurs while checking the validity of the data, echo a piece of JS code to prompt the error. As follows:

Echo "script" alert ('incorrect submission information'); script ";

Garbled characters are displayed in the pop-up box.

Problem analysis: If the browser sets automatic detection encoding, no garbled characters will occur. otherwise, garbled characters may occur. Because the JS code in the script tag is streaking without coding restrictions, garbled characters may occur.

Solution: a layer of HTML code is included in the pop-up error message. As follows:

$ Output = <

 

  Script alert ("$ errMsg"); script EOF; echo $ output;

 

In this way, when an error message is displayed, no gibberish occurs.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the error code garbled by using JS in PHP, including the content, and hopes to help friends who are interested in PHP tutorials.

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.