What should I do if the js output by PHP is not executed?

angryTom
Release: 2023-02-28 11:04:02
Original
3688 people have browsed it

What should I do if the js output by PHP is not executed?

The js output by PHP is not executed

<?php
    echo "<script>alert(&#39;我弹出来了&#39;)</script>";
?>
Copy after login

You can output the JS script in PHP to the browser in one sentence implement. (Recommendation: "PHP Tutorial")

But today I encountered a very strange problem, that is, this code just outputs a string under Chrom and Firefox, and is not executed. An alert pops up.

Principle:

MIME chrome does not parse text/plain. PHP can use header to output html, and the browser uses the last output header as content-type

header(&#39;Content-Type:text/html;charset=utf-8&#39;);
Copy after login

text/plain html will not be executed.

Just need to re-header before alert.

if(!uploadFile())
{
    echo "<script>alert(&#39;上传文件失败&#39;)</script>";    
}
header(&#39;Content-Type:text/html;charset=utf-8&#39;);
echo ("")
Copy after login

The above is the detailed content of What should I do if the js output by PHP is not executed?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template