views:

333

answers:

1

HTML5 will be next super star. So~~~How to using new idea to implement AJAX on the WebSocket in HTML5 spec? thx....

+4  A: 

I think you misunderstand ajax and websockets.

All internet programs operate by using a special kind of connection known as a socket (sockets can also be used for other things, but thats not important right now). For example, when you access a webpage in Chrome, Chrome creates a socket and uses that to connect to the webserver (there are other steps, but thats the simple explanation).

Ajax is a method for updating content on a page without reloading that page (or going to a new page), this is useful for dynamic content. Ajax works through the XMLHttpRequest object in the DOM Api. When you make an Ajax request, you're asking the web browser to initiate a new connection on your behalf (the web browser may then create a new socket as it sees fit).

Websockets is an alternative api which allows you more control over the socket the web browser creates. In essence its an alternative technology which accomplishes a similar purpose. Ajax sends only a single HTTP request (usually post or get), and receives the appropriate response, thus the advantage of websockets are 2 fold:

  1. Websockets allows for non HTTP transfers (for example, streaming VoIP).
  2. Websockets allow for bi-direction transfers, (ie. servers making follow up requests to client).

This is not to say Ajax isn't still useful, but that Websockets allow you to do things you can't with Ajax.

tzenes
i just have a concept,want to combine Websocket and Ajax.Maybe it's a guess...thx all
DonaldIsFreak
You should think of them as alternatives, not really something you can combine. If you tell me more about what you're trying to combine them to do, maybe I can help you.
tzenes