"; 3. Pass "var "serverData = document.body.getAttribute('serverData');" can be obtained and run."/> "; 3. Pass "var "serverData = document.body.getAttribute('serverData');" can be obtained and run.">
search
HomeBackend DevelopmentPHP ProblemWhat should I do if js cannot run php?

Solution to the problem that js cannot run php: 1. Specify the format file; 2. Modify the code writing to "

< ;/body>"; 3. Get and run it through "var serverData = document.body.getAttribute('serverData');".

What should I do if js cannot run php?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if js cannot run php?

Problem description:

Placing php in js does not execute

function gowechat (){ window.location.href="<?php $str=file_get_contents(&#39;http://weixin.qq.zoooe.com/?u=7nn7jj72rlms&#39;); echo $str; ?>;" }

What should I do if js cannot run php?

It is possible to write directly in the page Yes, but it won’t work when placed in .js. What’s going on?

Solution:

Only files in the format specified by the server will be parsed by the php server. js files are definitely not supported by the server, so no.

If it is an apache server, please check the

httpd.conf: <FileMatch &#39;.php$&#39;> ... </FileMatch>

part;

If it is nginx, please check the

nginx.conf: server { location ~ \.php$ { } }

I personally do not recommend this writing method. If you need to get some data from the server, you can do this:

 <body data-serverData="<?php echo $data; ?>"></body>

Then get it through js:

 var serverData = document.body.getAttribute(&#39;serverData&#39;);

My suggestion is that it is best to use the PHP template engine to handle the data interaction between the server code and the view. Question.

Recommended study: "PHP Video Tutorial"

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.