单击图像在我的代码中调用php函数 [英] calling a php function in my code with clicking an image
问题描述
我有一个php函数,当单击特定图像时,我希望在我的代码中运行它.当前,我在javascript中使用了onclick函数,但似乎每次刷新页面时都会运行该函数,而不是单击图像时.你们能帮我理解吗?我应该运行AJAX脚本吗?
I have a php function that I like to run in my code when a particular image is clicked. Currently I'm using an onclick function in javascript but it seems like the function is run everytime I refresh the page as opposed to just when I click the image. Can you guys please help me understand this? Should I be running a AJAX script?
推荐答案
这是一个执行顺序"问题:在将任何HTML呈现给用户之前,所有PHP代码都已执行.如果要基于用户操作执行PHP,则需要向服务器发起新请求(通过AJAX或标准链接).
This is an "order of execution" problem: All PHP code is executed before any HTML is presented to the user. If you want PHP to execute based on a user action, you need to initiate a new request to the server (via AJAX or a standard link).
这篇关于单击图像在我的代码中调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!