Reputation: 1
I recently developed a website for purchasing online. My problem is how I can create notification to alert at admin page when new order is inserted into MySQL. This notification will appear as an icon number at admin page on website, so that when admin open website they will know new order had made by customer.
I know we have to use javascript ajax but I have not idea how to begin.
I have some example code:
refreshInterval = 500
refreshTimeout = setTimeout(getNotificationCounts, refreshInterval);
function getNotifications() {
$.ajax({
url: 'path_to_your_php',
type: 'POST',
data: //put for example user_id but it cvan be handled by sesion as
dataType: 'json',
success: function (data) {
alert('You have' + data.total + ' new messages')
refreshTimeout = setTimeout(getNotificationCounts, refreshInterval);
}
});
}
Upvotes: 0
Views: 3944
Reputation: 17745
There are two alternatives for your problem. What you are looking for is persistent http connection.
How do I implement basic "Long Polling"?
Here you can find a basic example of what you want to do. It's detailed too.
Upvotes: 1