problem with ajax and ez publish

Author Message

justin kazadi

Friday 17 October 2008 1:48:35 am

hello,

i have a file in .../design/admin/templates/node/view/mytempltes.tpl. in this file i have this code :

{def $articles=fetch(content,list,hash(parent_node_id,2,
	                                                            class_filter_type,include,
	                                                            class_filter_array,array('myarticle')
	                                               )
	                     )
}
<form method="post" action={'content/action'|ezurl()}>
	                        
	     <select name="choix" id="monchoix"  onchange="recup_choix_select()">
	                      
	            <option >choisir une news</option>
	                        
	                       {foreach $articles as $child}
	                        
	            <option value="{$child.node_id}">{$child.name|wash()} {$child.object.id} </option>
	                                                     
	                        
	                        {/foreach}{undef $articles}
	                        
	    </select>
 </form>  

the functions

recup_choix_select()

send the selected value by ajax and load the file located in the same directory .../design/admin/templates/node/view/callajax.tpl. but the loaded file is the pagelayout.tpl located in the admin directory not the callajax.tpl.
the definition of the recup_choix_select function is:

function recup_choix_select(){
 var xmlhr = null;
if(window.XMLHttpRequest){// compatible Firefox ,opera et autres
xmlhr = new XMLHttpRequest();
}
else if(window.ActiveXObject){ // compatible Internet Explorer
 try {
   xmlhr = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
   xmlhr = new ActiveXObject("Microsoft.XMLHTTP");
 }
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xmlhr = false;
}
	
	xmlhr.onreadystatechange= function(){
		
		if(xmlhr.readyState == 4 && xmlhr.status == 200){
			
		resultat=xmlhr.responseText;
		document.getElementById("contenu_ajax").innerHTML=resultat;
	}
	}
var choix=
document.getElementById("monchoix").options[document.getElementById("monchoix").selectedIndex].value;
	xmlhr.open("post","callajax.tpl",true);
	xmlhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhr.send("ident="+choix);
	
}

i would like to know why the callajax.tpl it didn't loaded. the same code run wery good in an xhtml file.
thanks in advance.

The theory is when we know everything and nothing works.
The practice is when everything works and nobody knows why.
If the practice and theory are met, nothing works and we do not know why.

Albert Einstein

Yannick Komotir

Wednesday 22 October 2008 6:21:13 am

hi,
read this from http://ez.no/developer/forum/developer/xajax_developers

I haven't tried specifically xajax, but typically while working with YUI for example, I would create a new module/view where one of the params is a node_id something like

www.example.com/handlerequest/23

Then sending async get call you can get what you want from that URL as on PHP level you can fetch node_id = 23 then generate either XHTML output or whatever you need. You can pass of course more params, like www.example.com/handlerequest/23/JSON, where last part can be use for decision what output return.

You duty first create a module which interact directly with your XMLHttpRequest

or you can use xajax http://ez.no/developer/contribs/applications/xajax

Other article on Ajax http://ez.no/developer/articles/clean_up_your_applications_using_ajax

<|- Software Engineer @ eZ Publish developpers -|>
@ http://twitter.com/yannixk

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.