LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-22-2006, 01:05 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question sajax, php, entities, JS and IE


Well.... it's plenty of stuff.

I'm making an LDAP browsing application for our enterprise (web enabled).

It's made on PHP. I have already displayed the directory and can collapse / expand nodes. I have implemented node expansion with ajax (via sajax). In the PHP function that is called to get the information of the nodes I'm going to display I pass some information, like:
Node's Plain Name
Node's DN
Node's GUID
If the node has children among others. I separate each line by a \n and each node by an empty line (\n).

The JS code "parses" that input that's coming from sajax and creates the nodes and so on. It works flawlessly..... on firefox.

Not that it fails on IE, it works there too... but it fails when I have a html entity in my code (that I'm not decoding on php).

Things like "Enfermería" make the script fail from that point on.

Here's one output that the browser is supposed to handle (through my script that gets its input from sajax):
Code:
+:var res = 'a9d6d489976453488534e1188af6c956\n17\norganizationalunit \nAdiestramiento y Soporte\nOU=Adiestramiento y Soporte,OU=AIT,DC=FHEP,DC=ORG\n79560207a9c609438c5ad54d5cd641ff\ntrue\n\ngroup \nAnalista Web\nCN=Analista Web,OU=AIT,DC=FHEP,DC=ORG\n74cabd037763dc46a14ee777c25d4716\nfalse\n\norganizationalunit \nAnalista Web y Movil\nOU=Analista Web y Movil,OU=AIT,DC=FHEP,DC=ORG\nd0171519e267974095ce80065c80e430\nfalse\n\ngroup \nAplicacion Evaluaciones\nCN=Aplicacion Evaluaciones,OU=AIT,DC=FHEP,DC=ORG\n4c37585469b6c44598c8391be0dd7634\nfalse\n\ngroup \nAsesores\nCN=Asesores,OU=AIT,DC=FHEP,DC=ORG\nb6724ee1757bbc4d946713e457bba72c\nfalse\n\norganizationalunit \nAsesores SMILE\nOU=Asesores SMILE,OU=AIT,DC=FHEP,DC=ORG\n10bd2391ffb09f4f81e0d9914f605de8\ntrue\n\norganizationalunit \nCoordinacion de AIT\nOU=Coordinacion de AIT,OU=AIT,DC=FHEP,DC=ORG\n453e3eec097c7749bd5c9d036f799d51\ntrue\n\ngroup \nCoordinador de Sistemas\nCN=Coordinador de Sistemas,OU=AIT,DC=FHEP,DC=ORG\n4e9f8a768873eb47b8ffb76ecf680564\nfalse\n\norganizationalunit \nDigitalizaci�\nOU=Digitalizaci�,OU=AIT,DC=FHEP,DC=ORG\nef0d3df10db09f43ba76860f23e7e5b4\ntrue\n\norganizationalunit \nHardware\nOU=Hardware,OU=AIT,DC=FHEP,DC=ORG\n44606e18a8e7fe4db253b76b297ca433\ntrue\n\ngroup \nInforme de Errores SMILE\nCN=Informe de Errores SMILE,OU=AIT,DC=FHEP,DC=ORG\ne151e7eb1e6eb0489161\nfalse\n\ngroup \nPasante de Sistemas\nCN=Pasante de Sistemas,OU=AIT,DC=FHEP,DC=ORG\nb58bcb05975e6c4da0b92c028d543fc7\nfalse\n\ngroup \nSistemas Global\nCN=Sistemas Global,OU=AIT,DC=FHEP,DC=ORG\n25d1b4547518ed4abd65fa9a0dc72950\nfalse\n\norganizationalunit \nSoftware\nOU=Software,OU=AIT,DC=FHEP,DC=ORG\ne782dc21e66d0a4f9fd20d5ee508a852\ntrue\n\ngroup \nSoporte Administrativo\nCN=Soporte Administrativo,OU=AIT,DC=FHEP,DC=ORG\n80ab950ee499f74b8814e59a861e32fb\nfalse\n\norganizationalunit \nSoporte ASYS\nOU=Soporte ASYS,OU=AIT,DC=FHEP,DC=ORG\n9a612d71fe89314e9e04285f72e7a59e\ntrue\n\ngroup \nSoporte SMILE\nCN=Soporte SMILE,OU=AIT,DC=FHEP,DC=ORG\n3451e868f980ec47b316c2789432c58e\nfalse\n\n'; res;
The characters � are the special one that aren't being displayed well, but that they are being well transmitted. Checking with hexedit:
Code:
63 69 F3 6E
That would be "ción" from "Digitalización".

This is the JS code I use to parse the input and create the nodes:
Code:
function agregarNodos(resultado) {
	// en la primera linea esta el nombre de la tabla sobre la que estoy trabajando
	var posicion1 = resultado.indexOf("\n");
	var guid = resultado.substring(0, posicion1);
	posicion1++;
	var posicion2 = resultado.indexOf("\n", posicion1);
	var cantidad = parseInt(resultado.substring(posicion1, posicion2));
		
	// ahora pasamos a los nodos
	posicion1 = posicion2+1;
	var clase = "";
	var nombre = "";
	var dn = "";
	var guid2 = "";
	var hijos = false;
	var cadena = ""; // temporal
	var lista = document.getElementById(guid);
	
	var forma = document.forms["peticion"];
	for (var i = 0; i < cantidad; i++) {
		for (var j = 0; j < 6; j++) {
			posicion2 = resultado.indexOf("\n", posicion1);
		
			cadena = resultado.substring(posicion1, posicion2);
				
			switch (j) {
				case 0: 
					clase = cadena;
					break;
				case 1:
					nombre = cadena;
					break;
				case 2:
					dn = cadena;
					break;
				case 3:
					guid2 = cadena;
					break;
				case 4:
					hijos = cadena == "true" ? true : false;
					break;
				default:
			}
			posicion1 = posicion2+1;
		}
			
		var nodeLI = document.createElement("LI");
		var nodeText = document.createTextNode(nombre);
		if (hijos) {
			// 
			var field = forma.elements[guid2];
			
			// tiene hijos... hay que hacerlo expandible
			nodeA.href="javascript:toggle(\'" + guid2 + "\');"
			var nodeCruz = document.createTextNode(field ? "-" : "+"); // expandido?
			nodeA.appendChild(nodeCruz);
				
			nodeLI.appendChild(nodeA);
			// le agregamos un espacio al texto del nodo de texto
			nodeText.data = ' ' + nodeText.data;
			nodeLI.appendChild(nodeText);
			// agregamos la nueva lista
			var nodeUL = document.createElement("UL");
			nodeUL.id = guid2;
			nodeLI.appendChild(nodeUL);
				
			if (field) {
				// hay que expandir este campo tambien
				x_getNodes(guid2, agregarNodos);
			}
		} else {
			nodeLI.appendChild(nodeText);
		}
		lista.appendChild(nodeLI);	
	}
}
As you can see, I parse the input by looking for the new lines in the input string.

Any ideas how I can overcome the problem?
 
Old 08-22-2006, 01:58 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
I have noticed that IE, when it finds say: {á, é, í, ó, ú, ñ}, it will "skip" processing the following 2 characters. So Médica (por example) doesn't fail (though it shows up like "M?ca", but "Enfermería" at the end of one string will, because the \n will be processed as Enfermer?n and then continue with whatever follows just like it's a single line.

Well.... Do I have to blame M$? Or it's normal behavior?

Any idea how I can better parse it then?
 
Old 08-22-2006, 04:02 PM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
Solved it: on PHP (sajax side) I have to process this strings with non 7-bit ascii characters through rawurlencode() and then on the JS side use unescape() to get them back the way they were originally. :-) It worked on IE and on FF. :-D
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
pdftotext - How to output to html with ampersand entities ? narc Linux - Software 2 01-04-2006 02:34 PM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 11:05 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
Updating php 4.3.1 from tar and keeping current php configuration with mandrake 9.1 mrjeep Linux - General 0 04-02-2003 07:50 AM


All times are GMT -5. The time now is 10:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration