Come posso sviluppare un sistema di avviso come Facebook, dove Utente A aggiungi Utente B, Utente B otterrà un certo numero nella sezione Richiesta amico nell'intestazione come nell'immagine qui sotto. Come posso sviluppare qualcosa del genere? Come possiamo ottenere numeri come questo ?? come posso ottenere i codici in PHP e JQuery?
Come sviluppare un sistema di avviso come Facebook usando PHP e Jquery?
risposta
Presumo che si desidera un mezzo di allertare l'utente A, quando l'utente B 'amici' lui/lei senza la necessità di un aggiornamento della pagina?
Ciò richiede "AJAX". AJAX sta per Asynchronous Javascript e XML, ma questo è un termine sovraccarico ora-a-giorni con la reale struttura dei dati di scambio che spesso usa JSON invece di XML. JSON è JavaScript Object Notation. Ad ogni modo, l'idea è che la tua pagina web - senza essere aggiornata - possa effettuare chiamate periodiche al tuo server per ottenere informazioni nuove o aggiornate per aggiornare il display. Con PHP e jQuery, ti consigliamo di impostare prima la chiamata AJAX sulla tua pagina come questa:
$(function() { // on document ready
function updateAlerts() {
$.ajax({
url : "/check.php",
type : "POST",
data : {
method : 'checkAlerts'
},
success : function(data, textStatus, XMLHttpRequest) {
var response = $.parseJSON(data);
// Update the DOM to show the new alerts!
if (response.friendRequests > 0) {
// update the number in the DOM and make sure it is visible...
$('#unreadFriendRequestsNum').show().text(response.friendRequests);
}
else {
// Hide the number, since there are no pending friend requests
$('#unreadFriendRequestsNum').hide();
}
// Do something similar for unreadMessages, if required...
}
});
setTimeout('updateAlerts()', 15000); // Every 15 seconds.
}
});
Questa volontà, ogni 15 secondi, fare una richiesta al server presso l'url /check.php su lo stesso dominio dell'origine della pagina web. Il PHP dovrebbe interrogare il tuo database e restituire il numero di richieste di amici non letti. Forse qualcosa del genere:
<?php
function isValid(session) {
// given the user's session object, ensure it is valid
// and that there's no funny business
// TO BE IMPLEMENTED
}
function sanitize(input) {
// return CLEAN input
// TO BE IMPLEMENTED
}
// Be sure to check that your user's session is valid before proceeding,
// we don't want people checking other people's friend requests!
if (!isValid(session)) { exit; }
$method = sanitize($_POST['method']);
switch ($method) {
case 'checkAlerts' :
// Check DB for number of unread friend requests and or unread messages
// TO BE IMPLEMENTED
$response = ['friendRequests' => $num_friend_requests,
'messages' => $num_unread_messages ];
return json_encode($response);
exit;
case 'someOtherMethodIfRequired' :
// ...
exit;
}
?>
- 1. Un sistema facebook-come-notifica in php
- 2. come sviluppare si no conferma usando jquery
- 3. Come sviluppare una funzione di chat XMPP basata sul web usando PHP e JQuery?
- 4. Come posso creare un sistema "ricordami di me" usando PHP?
- 5. Come sviluppare firefox addon usando angularjs
- 6. come rendere il sistema di voto come stackoverflow usando ajax/jquery/php (efficiente)
- 7. Come gestire un messaggio di avviso di sistema per iOS?
- 8. Come disabilitare avviso e avviso in PHP nel file .htaccess?
- 9. Come creare un sistema di code PHP
- 10. Come disconnettersi usando l'SDK di Facebook?
- 11. Come sviluppare un sito web di streaming musicale utilizzando PHP
- 12. Come includere il file php usando Jquery?
- 13. Come ritagliare un'immagine usando jquery ajax e php?
- 14. Come posso iniziare a sviluppare per un web usando Scala?
- 15. Sviluppare un'esercitazione per l'app per facebook
- 16. Differenza PHP tra avviso e avviso
- 17. Come ottenere informazioni di sistema in PHP?
- 18. PHP - AJAX jQuery Server "Push" Sistema
- 19. Come sviluppare con akka e sbt?
- 20. Come sopprimere un avviso di terze parti usando warnings.filterwarnings
- 21. Cometa e PHP: Come usare Comet con un sistema di chat PHP?
- 22. Come passare un array usando PHP e Ajax in Javascript?
- 23. Aggiorna lo stato di Facebook esternamente usando PHP con username e password di un utente
- 24. Come gestire e sviluppare grandi progetti TYPO3?
- 25. Come caricare wp_editor usando Jquery?
- 26. Come posso stampare usando JQuery
- 27. Impostazione di $ _SESSION PHP ['var'] usando jQuery
- 28. Aggiornamento stato Facebook tramite php
- 29. Come sviluppare gemme?
- 30. Come sviluppare un lettore di codici QR multipiattaforma?
Non capisco, puoi spiegare un po 'di più? –
Come è? =) – mkoistinen
thks ..... questo aiuta davvero ... –