问题
I want to call a page (click.php) on a click of a button, click.php executes a php-mysql command that inserts a value into a table. Is there a way to click the button and have the page execute without page load. An example: when you do +1 rep on this website to someones post, Im assuming its database driven and when you give them rep, it adds +1. I want to do something basically like that. Is it possible with php, if not in javascript a way to call that page?
回答1:
Look into XMLHttpRequest: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=XHR
and Ajax : http://en.wikipedia.org/wiki/Ajax_(programming)
Basically:
create an XMLHttpRequest,
open your .php,
send(null) and viola, you're done.
What XHR does, is it requests the page in the background and loads it in the background. Thats pretty much all you need.
If you need the content of the page, you should look into XHR.onreadystatechange and XHR.responseText
来源:https://stackoverflow.com/questions/2331718/php-execute-page