Solution to the problem that the javascript code in the ThinkPHP controller cannot be executed, thinkphpjavascript_PHP tutorial

WBOY
Release: 2016-07-13 10:13:22
Original
647 people have browsed it

The solution to the problem that the javascript code in the ThinkPHP controller cannot be executed, thinkphpjavascript

The example in this article describes the solution to the problem that the javascript code in the ThinkPHP controller cannot be executed. Share it with everyone for your reference. The specific method is as follows:

Here is an example to analyze the solution to the problem that thinkphp's web page special effects code in the controller cannot be executed. Let's take the "Exit" item as an example. My "Exit System" link is written in the frame on the left. Use js dynamically generated. In other words, it cannot be specified through the target in the link.

Copy code The code is as follows:
$this->assign('jumpurl',__url__.'/login');
$ this->success("Logout successful!");

If you write it like this, the page to be jumped will be displayed in the right frame. Writing the js code into the url will not work, so I commented out these two lines of code. Use directly:
Copy code The code is as follows:
echo "<script>window.top.location.href='$url';</script> ";

This doesn't work either. On the one hand, the __app__ constants cannot be used in the URL. On the other hand, the final result of the execution is to remove the <script> tag and the rest is output directly! <br> <div class="codetitle"> <span><u>Copy code</u></span> The code is as follows:</div> <div class="code" id="code11957">(window.top.location.href='index/login';)</div> <br> I checked the success function in the action class and found no relevant parameters. <p>Then I suddenly thought of a question. The tags in tp are all enclosed by angle brackets (<>). Is the <script> I wrote in the controller parsed as a tag? So I re-wrote the second piece of code: <br> </p> <div class="codetitle"> <span><u>Copy code</u></span> The code is as follows:</div> <div class="code" id="code51478">echo '<literal><script>alert("Exit successfully");top.location.href= "login";</script>';

That's it.

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/916065.htmlTechArticleThe solution to the problem that the javascript code in the ThinkPHP controller cannot be executed, thinkphpjavascript This article tells the example that the javascript code in the ThinkPHP controller cannot be executed Implemented solutions. Share with everyone...
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!