Javascript-js value transfer tp framework

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.