This article describes the solution to the inability to execute javascript code in ThinkPHP controller. Share it for your reference. The specific methods are as follows:
Here, let’s analyze the solution to the problem that thinkphp’s web page special effect code cannot be executed in the controller. Take the “exit” item as an example. My “exit system” link is written in the framework on the left and is dynamically generated using js. That is to say, it cannot be specified through the target in the link.
If you write this way, the page you want to jump will be displayed in the right frame. It is not possible to write the js code into the url. I commented out these two lines of code. Use directly:
This is not possible. On the one hand, the constants such as __app__ cannot be used in the url. On the other hand, the final result is that the <script> tag is removed and the remaining direct output is!
I checked the success function in the action class and found no relevant parameters.
Later, I suddenly thought of a question. The tags in tp are all included in angle brackets (<>). Is the <script> I wrote in the controller parsed as a tag? So I rewrite the second code:
That's all.
I hope this article will be helpful to everyone's ThinkPHP framework programming.