Pass the value to the method on the common js page, and use the tp framework $. ajax ({code ...} this url has always reported an error. How can I write it? The error message is
Pass the value to the method on the common js page and use the tp framework.
$. Ajax ({
url:"{:U('User/contrast')}", data:{ enOldPassword:enOldPassword, userPassword_x:userPassword_x, }, type:'post', dataType: "json",
This url has always reported an error. How can I write it?
The error message is
Reply content:
Pass the value to the method on the common js page and use the tp framework.
$. Ajax ({
url:"{:U('User/contrast')}", data:{ enOldPassword:enOldPassword, userPassword_x:userPassword_x, }, type:'post', dataType: "json",
This url has always reported an error. How can I write it?
The error message is
Are you writing php in js?
If this section of JS is placed in the template file or referenced by the template file, it will take effect. If it is separately placed in the JS file, the U method will be invalid.
Solution:
1: place the JavaScript code in the template file;
2: Enter the url directly.
If the code is put on the template page, there is no problem, but if your page is placed in a separate js file, the above error will occur because it will not be rendered by TP.
The template parsing tag of tp conflicts with js {}. Generally, the TMPL_L_DELIM and TMPL_R_DELIM of tp are set to '<{' and '}>' respectively'
The address attribute has been added to the html page and can be obtained using attr in js.
You put this code in an independent js file, right? If yes, you can introduce this url before js.
var uploadurl={:U('User/contrast')}';
Then the AJAX url uses this global variable.
Ps: You need to figure out the TP tag, which can be used in the template, and finally converted into php code. But the js file is not part of the template.
Write a url directly. Do not use U.