środa, stycznia 31, 2007

Ajax ciekawostki

  1. Możliwość behavior z IE udostępniona w FireFox
  2. http://rabaix.net/index.php/en/articles/issues_developing_ajax_libraries -
    1. If you want to send special characters, like non-ASCII characters, you need to send them encoded in UTF-8. In this purpose, you can use the encodeURIComponent function.

      var params = "money="+ encodeURIComponent('€ euro');
      [...] request code [...]

    2. Request Referrer

      When a query is sent to the server, the referrer value in the query may be empty. However for some reasons the script, which handles the request, may require this information. The XMLHttpRequest comes with a method to send specific headers. It is not possible to set the referrer value for security reasons, however any other name can be used, like "X-Referrer" (read the warning note).

      var xmlRequest = getNewXmlHttpRequest();
      xmlRequest.setRequestHeader("X-Referrer",document.location);

      On the server side you can access to the referrer with $_SERVER['X_REFERRER'].
    3. ResponseXML jak do niego dotrzeć? var firstnames = reponseXML.getElementsByTagName('firstname'); alert('The firstname is ' + firstnames[0]);
    4. W przeglądarkach nie IE jest możliwość serializacji:
    5. function getTextVersion(XMLnode) {
      var text;
      try {
      //serialization to string DOM Browser
      var serializer = new XMLSerializer();
      text = serializer.serializeToString(XMLnode);
      } catch(e) {
      // serialization of an XML to String (IE only)
      text = XMLnode.xml;
      }
      return text;
      }

      node.innerHTML = getTextVersion(xmlResponse)
    6. Nie można wykonać dosztukowanego kodu z responseText - when you append the responseText with innerHTML method, browsers ignore all JavaScript’s codes. Some browsers may transform the innerHTML: Internet Explore ignores the JavaScript code and Firefox may have some strange behaviors.
    7. Przy responseXML nie działa getElementById - po prostu go nie ma.
    8. Jest pewna możliwość wykonania kodu zwróconego w 'response'XML/Text:
      1. responseXML:
      2. function launchJavascriptFromXML(responseXML) {
        var scripts = responseXML.getElementsByTagName('script');
        var js = '';
        for(var s = 0; s < scripts.length; s++) {
        if(scripts[s].childNodes[0].nodeValue == null) continue;
        js += scripts[s].childNodes[0].nodeValue;
        }
        eval(js);
        }
      3. responseText:
      4. function launchJavascript(responseText) {
        // RegExp from prototype.sonio.net
        var ScriptFragment = '(?:<script.*?>)((n|.)*?)(?:</script>)';

        var match = new RegExp(ScriptFragment, 'img');
        var scripts = responseText.match(match);

        if(scripts) {
        var js = '';
        for(var s = 0; s < scripts.length; s++) {
        var match = new RegExp(ScriptFragment, 'im');
        js += scripts[s].match(match)[1];
        }
        eval(js);
        }
        }
    9. Uwagi: są pewne zastrzeżenia co do bezpieczeństwa takiego rozwiązania. Dostęp tak wykonywanego kodu jest globalny do istniejących już zmiennych i funkcji. Funkcje stworzone w tak ściągniętym poprzez response kawałku są lokalne -niewidoczne dla załadowanego do tego momentu już kodu.
    10. Można włączyć w kod AJAX inny kod AJAX (embedded)
      1. var AJAX_Objects = new Array();
        function registerAjaxObject(name, obj) {
        AJAX_Objects[name] = obj;
        }
      2. function onreadystatechange_embeded() {
        // get back the object
        if(AJAX_Objects["xmlRequestEmbeded"].readyState == 4) {
        alert('Hello I came from onreadystatechange_embeded function embeded on the xml');
        }
        }

        var xmlRequestEmbeded = getNewXmlHttpRequest();
        xmlRequestEmbeded.open("GET", SERVER + "/data/issues_developing_ajax_libraries/test.xml");
        xmlRequestEmbeded.onreadystatechange = onreadystatechange_embeded;
        registerAjaxObject("xmlRequestEmbeded", xmlRequestEmbeded);
        xmlRequestEmbeded.send(false);
      3. function getNewXmlHttpRequest() {
        var obj = false;
        try {
        obj = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
        try {
        obj = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
        obj = new XMLHttpRequest();
        }
        }
        return obj;
        }
    11. Zasoby:
    12. Demo page of this article : http://rabaix.net/pub/issues_developing_ajax_libraries/demo.html
    13. Prototype library : http://prototype.conio.net/
    14. Wikipedia AJAX : http://en.wikipedia.org/wiki/AJAX
    15. Adaptive Path : http://www.adaptivepath.com/publications/essays/archives/000385.php
    16. Ajax Mistakes : http://sourcelabs.com/ajb/archives/2005/05/ajax_mistakes.html
    17. http://ajaxpatterns.org/On-Demand_Javascript

wtorek, stycznia 30, 2007

Podpis elektroniczny
Wymiana danych m. stroną w kliencie HTML (JS) a serwerem poprzez zakodowanie base64. Problem kompatybilności między bibliotekami PHP i JS realizujacymi ten algorytm. Na tej stronie (http://www.koders.com/javascript/fid42E166DF6E882BE462F10CF31A17973F7467BB10.aspx?s=base64) jest wiele algorytmów kodowania w różnym stylu dla JS.
http://forum.php.pl/lofiversion/index.php/t60745.html
http://forum.php.pl/index.php?showtopic=60027&hl=
Z jakiej biblioteki korzystasz? W Prototype jest cos takiego jak evalscript, o advAjax juz Seth pytal: http://forum.php.pl/index.php?showtopic=49058
Forum -http://forum.php.pl/lofiversion/index.php/f14.html
http://forum.php.pl/lofiversion/index.php/t57815.html
" witam



jeżeli to ie, strona jest w strefie zaufanej, użytkownik zgodzi się na odpalenie kontrolki to możesz utworzyć FileSystemObject i przy jego pomocy wyświetlać/tworzyć itd. pliki na dysku użytkownika. Pod FF musisz mieć podpisany skrypt i też można ... IMHO gra nie warta świeczki ...

pozdrawiam"


"http://forum.php.pl/index.php?showtopic=49058"


Adresy:

  1. http://www.smashingmagazine.com/2007/01/26/tutorials-round-up-ajax-css-javascript-php-mysql-and-more/
  2. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html - kompletny opis "permission" w Javie
  3. http://docs.rinet.ru/MIIS/ch22.htm - opis tworznia ActiveX w Control Pad
  4. http://blogs.zoho.com/creator/embed-forms-and-views-in-your-websiteblog - Zoho tworzenie formularzy w blogach
  5. http://www.hunlock.com/blogs/AJAX_for_n00bs - wymiana danych z serwerem poprzez iFrame (emulacja AJAX, choć bez kontroli)
  6. http://www.hunlock.com/blogs/AJAX_POST-It_Notes -zaleca się aby kodować wysyłane z JS (w kliencie znaki): " var passData = 'age='+escape(age)+'&name='+escape(name)+'&job='+escape(job);"
  7. http://www.hunlock.com/blogs/AJAX_from_the_darkside - jak zakończyć wysyłanie danych do klienta w PHP (poprzez zamknięcie polaczenia (ob_start();$size=...;header("Content-Length: $size");) i opróżnienie bufora (ob_end_flush(); flush();)
  8. http://support.microsoft.com/kb/241111/pl - Jak rozwiązać problemy z pobieraniem apletów...
  9. http://www.code-magazine.com/article.aspx?quickid=0404072&page=2 - VFP + .NET
  10. http://unspace.ca/discover/attributes/ - atrybuty czy klasy?
  11. http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=JavascriptStringConcatenation - klasa do pracy z łańcuchami w JS (a la Java)
  12. http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=MD5_For_AJAX - jak podpisywać MD5 z kluczem w JS, Javie i PHP
  13. http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro5/?ca=dgr-btw48Ajax Manipulowanie DOM-em (IBM)
  14. http://www-128.ibm.com/developerworks/xml/library/wa-ajaxintro4/ - AJAX i DOM (IBM)
  15. http://www.w3schools.com/jsref/jsref_obj_global.asp - ciekawe funkcje w JS (w3cschools)