23
Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeaux [email protected] WaterProof Software www.waterproof.fr 10 Novembre 2005

Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien [email protected] WaterProof Software 10

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

Forum PHP 2005

AJAX

Brillez avec vos applications web

Sébastien Hordeaux [email protected] Software www.waterproof.fr

10 Novembre 2005

Page 2: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 2Forum PHP 2005

Web 1.0: Synchrone

Action 1Action 2

Requête 1Page complète

Requête 2

Page complète

Nouvelle pagePage 1Page 2Page 3

Attente

Page 3: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 3Forum PHP 2005

Web 1.0: Synchrone

• Représentatif de l’architecture physique• Attente entre chaque action• Evènements limités

– Liens hypertextes– Validation de formulaire (submit)

Impossible de créer des applications web aussi intuitives et efficaces

que les applications client lourd

Page 4: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 4Forum PHP 2005

Web 2.0: AsynchroneL’utilisateur peut continuer

a interagir avec l’application sans attendre

Action 1Action 2

Requête 1Retour de l’appel

Requête 2

Retour de l’appel

Page 1

Page 5: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 5Forum PHP 2005

Web 2.0: Asynchrone

• Plus d’attente entre chaque action• Possibilités d’interactions plus importante

– onBlur– onKeyPress– onHover– setTimeout

Possible de créer des applications web aussi intuitives et efficaces

que les applications client lourd

Page 6: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 6Forum PHP 2005

AJAX?

• Asynchronous Javascript And Xml– Asynchrone– Javascript– XML

Page 7: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 7Forum PHP 2005

AJAX: Concrètement

• Changer l'affichage grâce au DOM• Modifier le comportement du navigateur

grâce à Javascript• Répondre aux événements utilisateurs

grâce au DHTML (clavier & souris)• Appels distants

– XmlHttpRequest– Frames

Page 8: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 8

Tant de bruit pour AJAX? (1/2)

• Technologie ancienne– Premières utilisations en 1999

Forum PHP 2005

Page 9: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 9Forum PHP 2005

Tant de bruit pour AJAX? (2/2)• Effet Google (GMail, GoogleMap, GoogleSuggest…)• Frustrations générées par les applications web• Utilisation de plus en plus importante du web

– Utilisation nomade (Domicile, Bureau, Voyage…)– Tendance actuelle 100% web– Meilleure infrastructure (ADSL, Cable…)

• Rapidité de déploiement des mises à jour• Indépendant des plugins• Portable (Mac, Linux, Windows)• Supporté par une grande quantité de navigateurs

Page 10: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 10Forum PHP 2005

Inconvénients (1/2)• Ne gère pas toutes les contraintes liées au web

– Stocker des informations localement– Interagir avec le hardware (Imprimantes, Webcams, Scanner…)

• Nécessite que Javascript soit activé• Gérer les cas où AJAX n'est pas disponible (Graceful Downgrade)• Risque de changer les habitudes des utilisateurs

– Difficulté de placer des signets sur une page ou un état de l’application– Bouton précédent

• Nécessite l'apprentissage de langages supplémentaires (Javascript, DOM)

• Dépendance importante du réseau– Latences réseau– Connexion internet– Performances (Risque de surcharger le serveur si trop de callbacks)

• Déboguage plus difficile

Page 11: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 11Forum PHP 2005

Inconvénients (2/2)

• Compatibilité système d'exploitation (Mac)• Compatibilité navigateurs

Page 12: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 12Forum PHP 2005

XmlHttpRequest (1/2)

• Permet de faire les appels distants• Construction différente selon les navigateurs

/*@cc_on @*//*@if (@_jscript_version >= 5)// JScript gives us Conditional compilation, we can cope with old IE versions.// and security blocked creation of the objects.try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (E) {xmlhttp = false;

}}@end @*/if (!xmlhttp && typeof XMLHttpRequest!='undefined') {xmlhttp = new XMLHttpRequest();

}

Page 13: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 13Forum PHP 2005

XmlHttpRequest (2/2)

• Manipulation du retour– XML: object.responseXML– Brute: object.responseText

• HTML: remplacer le contenu de div…• Javascript: évaluation par le navigateur

Page 14: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 14Forum PHP 2005

Exemple simple

function updateCityState() {if (!isWorking) {

var zipValue = document.getElementById("zip").value;xmlhttp.open("GET", url + escape(zipValue), true);isWorking = true;xmlhttp.onreadystatechange = handleHttpResponse;xmlhttp.send(null);

}}

<input size="5" name="zip" id="zip" onblur="updateCityState();" type="text">

function handleHttpResponse(){if(xmlhttp.readyState == 4){

isWorking = false;if(xmlhttp.responseText.indexof('invalid') == -1){var xmlDocument = xmlhttp.responseXML;var city = xmlDocument.getElementByTagName('city').item(0).firstChild.data;var state = xmlDocument.getElementByTagName('state').item(0).firstChild.data;document.getElementById('city').value = city;document.getElementById('state').value = state;

}}

}

Page 15: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 15Forum PHP 2005

Quelques framework existants• Cpaint

– http://cpain.sourceforge.net/• PEAR: HTML_AJAX

– http://pear.php.net/package/HTML_AJAX• Sajax

– http://www.modernmethod.com/sajax/• JPSpan

– http://jpspan.sourceforce.net/• Symfony (Solution française)

– http://www.symfony-project.com/

Page 16: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 16Forum PHP 2005

Sajax

• Lien entre rapportsrequire_once('Sajax.php');sajax_init();global $sajax_request_type;$sajax_request_type = 'GET';sajax_export('getIssueSummaryById');sajax_handle_client_request();// ...// Include le code JS pour le navigateurecho sajax_get_javascript();

<script language="Javascript" type="text/javascript">// Inclure le code nécessaire depuis le serveur renvoyé par sajax_get_javascript

function do_getIssueSummaryById_display(issueSummary) {document.getElementById("IssueSummaryField_Id").innerHTML = issueSummary;

}

function do_getIssueSummaryById() {var issueId;issueId = document.getElementById("IssueIdField_Id").value;x_getIssueSummaryById(issueId, do_getIssueSummaryById_display);

}</script>

function getIssueSummaryById($issueId){return '[issue caption]';

}

Page 17: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 17Forum PHP 2005

JPSpan (1/3)

• Accélérer le chargement de l’application– Chargement à la demande

• Économiser de la bande passante

• DEMONSTRATION

• wIT: http://www.waterproof.fr/wit/

Page 18: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 18Forum PHP 2005

JPSpan (2/3)class HistoryManager {

function GetHistory($IssueId){

return utf8_encode('[Issue History]');}

} require_once 'JPSpan.php';require_once JPSPAN . 'Server/PostOffice.php';$S = &new JPSpan_Server_PostOffice();$S->addHandler(new HistoryManager());if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'], 'client') == 0) {

define('JPSPAN_INCLUDE_COMPRESS', true);echo $S->getClientCode();

} else {define ('JPSPAN_ERROR_MESSAGES', false);require_once JPSPAN . 'ErrorHandler.php';$S->serve(false);

}

Page 19: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 19Forum PHP 2005

JPSpan (3/3)<script type="text/javascript" src="ajaxHistory.php?client"></script><script type="text/javascript">function LoadHistory(){if(typeof(historymanager) != undefined){

var ajaxCallbackHistory = {gethistory: function (response) {

document.getElementById('history-content').innerHTML = response;}

}var ajaxHistoryServer = new historymanager(ajaxCallbackHistory); ajaxHistoryServer.gethistory(issueId);document.getElementById('history-loader').style.display = 'none';DisplayUiMessageHistory('Please wait while history is being loaded...');

}return true;

}</script>

Page 20: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 20Forum PHP 2005

Démonstration

• Éviter les chargements de pages inutiles

• DEMONSTRATION

• wIT: http://www.waterproof.fr/wit/

Page 21: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 21Forum PHP 2005

Autres exemples• Bureau virtuel: http://www.start.com/• Suggestion

– Kayak: http://www.kayak.com/s/kayaksearch.jsp?tab=flights

– Google Suggest: http://www.google.com/webhp?complete=1• GMail: http://gmail.com/

• GoogleGroup: http://groups.google.com/• GoogleMap: http://maps.google.com/• Agenda / Calendrier: http://www.kiko.com/• Suivi du temps passé:

http://www.formassembly.com/time-tracker/• Ta-Da List: http://www.tadalist.com/

Page 22: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 22Forum PHP 2005

Informations sur AJAX

• http://www.ajaxpatterns.org/• http://www.ajaxian.com/• http://blog.joshuaeichorn.com/• http://www.ajaxreview.com/• http://www.ajaxdeveloper.org/• http://ajaxblog.com/• http://www.robsanheim.com/Ajax/

Page 23: Brillez avec vos applications web - AFUP · 2018. 8. 18. · Forum PHP 2005 AJAX Brillez avec vos applications web Sébastien Hordeauxshordeaux@waterproof.fr WaterProof Software 10

10 Novembre 2005 23Forum PHP 2005

Questions & Réponses

• Merci de votre attention

• Pour continuer le dialogue:– Mail: [email protected]– Web: http://www.waterproof.fr/