开发者

What is the need of JavaScript while developing a page?

I have been developing websites for some time now and I hardly use any Javascript in my pages.

Whatever I can want to do with JavaScript, it is possible through PHP. Just like ajax itself. We can send a regular request instead开发者_StackOverflow中文版 of a ajax request, can't we? We can use "include" to include sub part of pages.

So am i missing something about javascript, that I dont know of?


The point of Javascript is that it is a client side technology. It allows you to do stuff on the browser instead of the server.

Simple example - you want to let the user enter some numbers and then you perform some calculation on these and display the results.

With Javascript, this would all happen on the browser, the server will not be involved.

If however, you didn't use Javascript, the data would need to be posted to the server and you will need to calculate and display with the server, using server resources.

Javascript allows you to move expensive operations to the client.


Take for instance Stack Overflow. If someone posts an answer while you are writing one, a popup will come out saying "there is a new answer". Note that the page is not reloaded in this process.

That would not be possible by only using PHP: although it does make use of a server-side language to query for new answers, this is called in background using Javascript (this is an example of AJAX).


Also, with PHP you cannot catch user interaction with the site, as once the PHP page is loaded the server doesn't know anything about what is going on in the client.


JS allows you to respond to users interacting with a page (such as moving the pointer over an element) and to perform operations without a (relatively) expensive round trip to the server.


The comprehensive jQuery library will allow you to animate smoothly with various different effects (sometimes with better results than flash).

AJAX also allows for no-page refreshes, pages can be updated on-the-fly.

jQuery: http://www.jquery.com/ User Interface demos: http://jqueryui.com/demos/

With response to that comment below from @silky:

There are many more circumstances where using JavaScript is the only option. How about events? JavaScript is the only language available for having your website communicate with the browser and watch for events: clicks, double clicks, mouse enters, mouse exits, key presses, browser window sizing... the list goes on. If you need access to those events, you are in JavaScript territory.

Taken from: http://css-tricks.com/you-know-you-should-use-javascript-when/


If you want your website to be more user friendly and easy to use you will need javascript.

Would you wait till this website (Stackoverflow.com) refresh your page, to see your comment updated?


Its the language for programming the web agnostic of any platform Windows, Linux etc. It can be used to do both client and server side development.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜