_php example of using JS variable method in twig

Source: Internet
Author: User
Tags php template smarty template
In this paper, we describe the method of using JS variable in twig. Share to everyone for your reference, as follows:

Look at a piece of code first

 

The address of this AJAX request is not properly accessible.

In this code, JQuery ("#my_input"). Val () values are assigned to value, and then you want to introduce the value variable into the URL address in Ajax.

At this point you will find that the value of the address you are visiting is not introduced, but is treated as a string.

That is, the value of JS can not be directly quoted in the Twig.

The reason is that twig parses a PHP variable, and value is a JS variable, so twig is considered a string by default.

So we need to replace, we'll use replace.

The code below, you can compare with the above code itself:

 

Permanent address of this article: http://blog.it985.com/7020.html
This article is from IT985 blog, please indicate the source and corresponding link when reproduced.

More about PHP template related content readers can view the site topics: "PHP Template Technology Summary", "Smarty Template Primer Basic Tutorial", "CodeIgniter Introductory Tutorial" and "thinkphp Introductory tutorial"

I hope this article is helpful to you in PHP programming.

  • Related Article

    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.