AJAX VS PHP用于动态网页?

时间:2022-12-05 13:54:31

Why use AJAX for dynamic web pages when you can do it only with php?

为什么只在使用php时才能将AJAX用于动态网页?

3 个解决方案

#1


14  

The main reason to bother with AJAX is User Experience (UX).

打扰AJAX的主要原因是用户体验(UX)。

Now AJAX won't necessarily improve UX in every single instance so in a lot of places sticking with pure PHP is perfectly okay.

现在AJAX不一定会在每个实例中改进UX,因此在很多地方坚持使用纯PHP是完全可以的。

But imagine the case where you have a text field on the site and a link to vote on something. Kinda like this site. When you add AJAX your users won't loose the text they entered in the textfield when they decide to vote on the link! How incredibly useful!

但想象一下,你在网站上有一个文本字段和一个投票的链接。有点喜欢这个网站。当您添加AJAX时,当用户决定对链接进行投票时,他们不会丢失他们在文本字段中输入的文本!多么有用!

So if you care about your user's experience it is a good idea to use AJAX in situations like that.

因此,如果您关心用户的体验,那么在这种情况下使用AJAX是个好主意。

#2


5  

PHP creates and outputs the Content to the Client Browser as it's a Server-Side Language and that's what it was built for, so on a request your code will access database, files etc. and then output the constructed html/text to the client.

PHP创建内容并将其输出到客户端浏览器,因为它是服务器端语言,它就是为它构建的,因此在请求时,您的代码将访问数据库,文件等,然后将构造的html /文本输出到客户端。

Ajax just gives the User a more Desktop like feel. For example deleting a record and instead of the entire page reloading just letting the one element disappear from say a list and letting the server know that the record is to be deleted. But Remember to let the User know when you are busy sending data to the server (With a progress bar in .gif format for example). As lot's of user feel that if nothing happens on the screen to notify them, that the application is frozen which means they will either reload the page or just try to click the button again.

Ajax只是为用户提供了更像桌面的感觉。例如,删除记录而不是整个页面重新加载只是让一个元素从列表中消失并让服务器知道要删除记录。但请记住,当您忙于向服务器发送数据时,请告知用户(例如,使用.gif格式的进度条)。因为很多用户认为如果屏幕上没有任何反应通知他们,应用程序被冻结,这意味着他们将重新加载页面或者只是尝试再次单击该按钮。

But you will need to provide some sort of compatibility with browsers that have Javascript disable and thus cannot use your AJAX functions, just something to keep in mind.

但是你需要提供某些与Javascript禁用的浏览器的兼容性,因此不能使用你的AJAX函数,只需记住一些事项。

#3


2  

AJAX stands for Asynchronus Javascript and XML, meaning that a page can get new data, without having to reload a page.

AJAX代表Asynchronus Javascript和XML,这意味着页面可以获取新数据,而无需重新加载页面。

PHP cannot send data without reloading the whole page. A user has to press a button, to send data.

PHP无法在不重新加载整个页面的情况下发送数据。用户必须按下按钮才能发送数据。

An example of AJAX is for example google suggestions or the tag suggestions on this website.

AJAX的一个例子是谷歌的建议或本网站上的标签建议。

#1


14  

The main reason to bother with AJAX is User Experience (UX).

打扰AJAX的主要原因是用户体验(UX)。

Now AJAX won't necessarily improve UX in every single instance so in a lot of places sticking with pure PHP is perfectly okay.

现在AJAX不一定会在每个实例中改进UX,因此在很多地方坚持使用纯PHP是完全可以的。

But imagine the case where you have a text field on the site and a link to vote on something. Kinda like this site. When you add AJAX your users won't loose the text they entered in the textfield when they decide to vote on the link! How incredibly useful!

但想象一下,你在网站上有一个文本字段和一个投票的链接。有点喜欢这个网站。当您添加AJAX时,当用户决定对链接进行投票时,他们不会丢失他们在文本字段中输入的文本!多么有用!

So if you care about your user's experience it is a good idea to use AJAX in situations like that.

因此,如果您关心用户的体验,那么在这种情况下使用AJAX是个好主意。

#2


5  

PHP creates and outputs the Content to the Client Browser as it's a Server-Side Language and that's what it was built for, so on a request your code will access database, files etc. and then output the constructed html/text to the client.

PHP创建内容并将其输出到客户端浏览器,因为它是服务器端语言,它就是为它构建的,因此在请求时,您的代码将访问数据库,文件等,然后将构造的html /文本输出到客户端。

Ajax just gives the User a more Desktop like feel. For example deleting a record and instead of the entire page reloading just letting the one element disappear from say a list and letting the server know that the record is to be deleted. But Remember to let the User know when you are busy sending data to the server (With a progress bar in .gif format for example). As lot's of user feel that if nothing happens on the screen to notify them, that the application is frozen which means they will either reload the page or just try to click the button again.

Ajax只是为用户提供了更像桌面的感觉。例如,删除记录而不是整个页面重新加载只是让一个元素从列表中消失并让服务器知道要删除记录。但请记住,当您忙于向服务器发送数据时,请告知用户(例如,使用.gif格式的进度条)。因为很多用户认为如果屏幕上没有任何反应通知他们,应用程序被冻结,这意味着他们将重新加载页面或者只是尝试再次单击该按钮。

But you will need to provide some sort of compatibility with browsers that have Javascript disable and thus cannot use your AJAX functions, just something to keep in mind.

但是你需要提供某些与Javascript禁用的浏览器的兼容性,因此不能使用你的AJAX函数,只需记住一些事项。

#3


2  

AJAX stands for Asynchronus Javascript and XML, meaning that a page can get new data, without having to reload a page.

AJAX代表Asynchronus Javascript和XML,这意味着页面可以获取新数据,而无需重新加载页面。

PHP cannot send data without reloading the whole page. A user has to press a button, to send data.

PHP无法在不重新加载整个页面的情况下发送数据。用户必须按下按钮才能发送数据。

An example of AJAX is for example google suggestions or the tag suggestions on this website.

AJAX的一个例子是谷歌的建议或本网站上的标签建议。