0

SQL クエリを実行し、レコードを 2D 配列に保存した php ページがあります。ここで、ユーザーの要件に従ってそのデータを操作したいと思います。そのために、そのphpページにさまざまなボタンを付けました。

ボタンがクリックされるたびに、ページをリロード/更新せずに、関連付けられた関数を実行したいと考えています。私を助けてください。ありがとう

4

1 に答える 1

0

The technology you are looking for is called an asynchronous HTTP request (Ajax), the most common implementation of which is achieved using jQuery (http://api.jquery.com/jQuery.ajax/).

Essentially your PHP function is on the remote server. Usually this is only accessible to the client (your visitors browser) at the time of page reload. Once the page is rendered, the html your visitor is seeing in their browser, and the php code which rendered this are on two systems, and traditionally where only able to communicate during an http request (a page reload almost by definition).

By using clientside javascript (Ajax), it is possible for you to access your php function from the clientside. It still runs on the server, however the ajax call can retrieve the result of this and return it to your page without a reload.

The normal way to program such a functionality is to put in place your php function as if your visitor did not have javascript enable, hence providing a fallback in this situation.You can then intercept the 'submit' event on the button that calls your function, and instead send the same data to and from the server using ajax.

I can help with an example if you could provide code, though hopefully this should be enough to point you in the right direction.

于 2013-11-10T15:23:31.457 に答える