jquery - create notification when user insert new order into database in php -


i developed website purchasing online. problem how can create notification alert @ admin page when new order inserted mysql. notification appear icon number @ admin page on website, when admin open website know new order had made customer.

i know have use javascript ajax have not idea how begin.

i have example code:

refreshinterval = 500 refreshtimeout = settimeout(getnotificationcounts, refreshinterval);  function getnotifications() {   $.ajax({     url: 'path_to_your_php',     type: 'post',     data: //put example user_id cvan handled sesion         datatype: 'json',     success: function (data) {       alert('you have' + data.total + ' new messages')       refreshtimeout = settimeout(getnotificationcounts, refreshinterval);     }   }); } 

there 2 alternatives problem. looking persistent http connection.

  1. if don't mind browser support of solution, use websockets. part of html5 api not supported browsers , it's new thing there support on new versions only. check here more http://www.html5rocks.com/en/tutorials/websockets/basics/
  2. the second alternative long polling. basic idea client makes ajax call server periodically doesn't return immediately, returns if server has response, or if specific amount of time has been reached. simple polling too, it's not practice because make lot of calls server no reason of time. long polling technique known comet technique. that, , come more focused questions.

how implement basic "long polling"?

here can find basic example of want do. it's detailed too.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -