Home > Backend Development > PHP Problem > What should I do if js cannot run php?

What should I do if js cannot run php?

藏色散人
Release: 2023-03-17 12:16:01
Original
1997 people have browsed it

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; ?>;" }
Copy after login

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>
Copy after login

part;

If it is nginx, please check the

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

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>
Copy after login

Then get it through js:

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

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!

Related labels:
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