How to bind php code to html elements as click events?

Source: Internet
Author: User
Previously, the php code was redirected to a specific php page to execute the corresponding code. Can I bind a piece of code and a click event like a js Code, and then click it to execute this php code, do not need to jump to other pages? Previously, the php code was redirected to a specific php page to execute the corresponding code. Can I bind a piece of code and a click event like a js Code, and then click it to execute this php code, do not need to jump to other pages?

Reply content:

Previously, the php code was redirected to a specific php page to execute the corresponding code. Can I bind a piece of code and a click event like a js Code, and then click it to execute this php code, do not need to jump to other pages?

I want to click something, such as a button, and then execute a database operation to insert a row of records. Is it implemented using ajax?

Ajax is the most simple. I have done a similar simple demo a long time ago. You can take a look at it. The ajax encapsulated with Jq is very simple.
Ajax code: pass a value to php, receive the parameters returned by php, and enter them in html.
PHP processes database code and returns relevant content

The code is mounted on SAES. For local testing, you can modify conf. php or use the existing code mazuguang.sinaapp.com.
Hope to help you, Luck!

If you can solve your problem, you are welcome to adopt ~

If possible, output the clicked content to the page and hide it. Click it to display it. Otherwise, use ajax.

Php code has been executed when you render the page. You want to click it to execute 1. Write it as js call 2. ajax execute and return the result.

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.