适合这种情况的技术是什么? [关闭]

I am currently programming a community forum and i have a scenario where a user can say thank you to a specific post by clicking a button

that button should trigger multiple sequences checking things with mysql databases and such but i cannot think of an effective way to load/initiate a separate php file without leaving the page, or needing to refresh it.

i can use javascript to give the impression that your click went thru and was properly processed without needing to refresh the page,but i cannot use javascript to run mysql queries or something of that kind.

so what exacly can i do here?

this is very similar to pressing "upvote/downvote" on StackOverflow since its instant and doesnt require reloading of the page.. so what is SO using for example to achieve this?

additional information: i cannot make the server load the php file or something of that sort because i need the user session for it to work!

thank you alot for your help.

It sounds like you just want to use an Ajax call which allows Javascript in your page to send an HTTP request (e.g. an URL or form) to a server. The server (your PHP in this case) processes that request and returns the response back to the Javascript in the page, all without doing anything to the current page. The user session (assuming it is cookie-based) will be sent with the request automatically so your PHP server will have access to the session.

The Javascript in the page can then do anything it wants with the response (nothing, modify the contents of the page, report new status, etc...).

Here's an intro to Ajax: https://developer.mozilla.org/en-US/docs/AJAX

This is a widely used technology and it is exactly what is used by StackOverflow when you upvote or downvote.

I might also mention that basic Ajax requests are fairly straightforward in plain Javascript (you can usually copy an example to get started), but it is often useful to use a library such as jQuery which offers many features on top of the Ajax infrastructure which can be useful and save you a lot of time.