/    Sign up×
Community /Pin to ProfileBookmark

Button executing a php function using AJAX

I would like to have a button execute a php function using AJAX.

The button and AJAX functioning must be in the same webpage.

Please give examples.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMay 30.2014 — 1 - you don't execute a php function from anywhere but INSIDE php. To be correct you should be saying "script".

2 - You can't execute php from a webpage. You can execute JS but not php. A webpage is what is on your client pc, comprised of html and perhaps js, and therefore cannot run php.

3 - This means that what you are really asking is "How to make an ajax call". I'd try google first. Many examples of it out there.

How does ajax work? An event in your webpage triggers a JS function. The event can be a click on an anchor, a button, or even a change event on an html tag. In that JS function you have some JS code that sets up the ajax call which then executes a separate process ON YOUR SERVER wherein PHP code runs to do your desired task. Once the task is complete it sends back a result that your JS code (waiting in a loop for the results) receives and interprets and posts to your webpage or does whatever your ultimate purpose is.
×

Success!

Help @Philosophaie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...