: 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.