Solution for bringing the thinkphp u method into JS Variables

Source: Internet
Author: User
Provides various official and user-released code examples and code reference. You are welcome to exchange and learn. I think many of my friends have been so confused. Anyway, I have been confused for a long time, when using TP to write the linkage function, you will find out how to pass the superior ID obtained using js to the Controller method using the U method to obtain the sublevel list. Return to the page. Like provinces and cities, switching provinces must obtain cities in the response provinces. I personally think my methods are fine, so I will share with you.
First, the JS variable is brought into the U method in the form of a string, and then it is OK to replace it with the js replacement function. Var province_id = 3; // variable to be included
Var str = "{: U ('Article/getcity', array ('pid '=> 'vince _ id '))}"; // Add the variable to the U function as a string first
Str1 = str. replace ("province_id", province_id); // replace the string that replaces the variable with the real variable. OK!
$ ("# City_id"). load (str1 );

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.