创建对 PHP 函数的 jQuery AJAX 请求

创建对 PHP 函数的 jQuery AJAX 请求

问题描述:

到目前为止,在创建 AJAX 请求时,我一直在发布到单独的 PHP 文件.是否可以创建一个调用 PHP 函数而不是发布到单独页面的 jQuery AJAX 请求?

So far when creating AJAX requests I have been posting to a separate PHP file. Is it possible to create a jQuery AJAX request that calls a PHP function rather than posts to a separate page?

如果您能向我发送任何示例或文档,那就太好了.

If you could send me any examples or documentation would be great.

AJAX 请求调用的是 URL(发起 HTTP 请求),不是文件,大多数情况下 URL 是由服务器翻译的指向一个文件(或您的情况下的 php 脚本),但是从 HTTP 请求到收到的响应发生的一切都取决于您(在您的服务器上).

AJAX requests call a URL (make a HTTP request), not a file, in most cases the URL is translated by the server to point at a file (or a php script in your case), but everything that happens from the HTTP request to the response that is received is up to you (on your server).

有许多 PHP 框架将 URL 映射到特定的 php 函数,AJAX 只是一种访问 URL 并接收响应的异步方式.

There are many PHP frameworks that map URL's to specific php functions, AJAX is just an asynchronous way to access a URL and receive a response.

所述 URL CAN 触发服务器调用特定函数并返回响应.但是由您来构建您的 URL 和服务器端代码.

Said URL CAN trigger the server to call a specific function and send back a response. But it is up to you to structure your URL's and server side code as such.