Get the App
SLTechnology News&Howtos  ›  Development  › 

What if the U method in the thinkPHP js file is not parsed

Shulou Source: shulou.com Published: 2022-06-03 20:24:06 11月12日 Update

This article mainly introduces the thinkPHP js document U method is not parsed how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

The details are as follows:

I want to write ajax in the js file

Found an exception after writing

I thought that ajax was not supported in the js file.

Later found that the address resolution error.

That is, the U method is not parsed in the js file.

It looks like thinkphp parses some elements in the tpl file.

Ajax in js file

Function ajaxCheckTel (tel,id) {var res ='; $.ajax ({type: "post", url:ajaxurl, / / address resolution error, U method in js file will not be parsed by thinkphp data: "todo=checktel&tel=" + tel+ "& id=" + id, async:false, success:function (msg) {res = msg;}}); if (res = = 1) {return true;} else {return false;}}

Ajaxurl can only be used instead, and after the variable is parsed in tpl, it is passed into the js file so that the address is correct.

Var ajaxurl = "{sh::U ('Merchant/ajax')}"; / / used in merchant.js

As you can see, variables in js also have ranges, such as ajaxurl, which can be referenced in multiple js functions.

Thank you for reading this article carefully. I hope the article "what if the U method is not parsed in the thinkPHP js file" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Files methods articles variables addresses what to do support that is values elements interests functions at the same time multiple size more friends thus knowledge editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker macOS Shulou Information vpn