-1

I have just started studying Ajax for making my own chat application using MySQL, PHP, JavaScript and Ajax.
I have almost made my application but the problem is that I have used setInterval so my box in which chat log is displayed it is fetched from the database every second and displayed,and this is inefficient.

Rather I want that the database is accessed only when there is some change in the database ,that is, when a user sends a message and the database is changed then only the database is fetched by other users message box.

rtruszk
  • 3,868
  • 13
  • 33
  • 53

1 Answers1

3

I asked this question a while back and got this answer which helped me immensely:


You are looking to PUSH data, which requires Websockets (see 1, 2, 3). If you are using a Javascript library like Node.js, they have support for this.

What you'll need is a Websocket server (something that actually pushes). There are Websocket servers for PHP (see 1, 2, 3). And the Websocket client (Javascript that receives the "push" and processes it). Please check out the links I've included for further research.

Community
  • 1
  • 1
Ben
  • 8,696
  • 7
  • 37
  • 72
  • Actually it is a part of my college project and i am required to complete this using ajax only ,So can i make my project better,that is ,have some kind of a workaround for this set interval that i m using ,using ajax only? I can pm u a copy of my project,if u have the time, will be truely greatful :) – Ravish Mahur Jul 01 '15 at 07:53
  • If you'd like to pay me, sure I'll take a look! But I don't think that there's a way to do what you're looking for with AJAX only. – Ben Jul 01 '15 at 08:00
  • ok thanx for your input :) – Ravish Mahur Jul 01 '15 at 08:12