SoFunction
Updated on 2025-04-03

Solution to javascript alert garbled code

The javascript alert() function is a function for input prompts, but today when using alert() prompts, there is no problem with Chinese garbled code, pinyin and other things. I will find a solution in the forum below, and I will share it with you below.
Solution 1:
Copy the codeThe code is as follows:

echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
echo '<script type="text/javascript">alert("Added successfully")</script>';

Solution 1:
If you are using external calls
Copy the codeThe code is as follows:

<script language="javascript" type="text/javascript" src=""></script>

If js and page encoding are not counted, garbled code may occur. The solution is
charset="gb2312" added in js
Copy the codeThe code is as follows:

<script charset="gb2312" language="javascript" type="text/javascript" src=""></script>

The problem has been solved.