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.

eZ debug

Timing: Jan 18 2025 16:25:38
Script start
Timing: Jan 18 2025 16:25:38
Module start 'layout'
Timing: Jan 18 2025 16:25:38
Module start 'content'
Timing: Jan 18 2025 16:25:38
Module end 'content'
Timing: Jan 18 2025 16:25:38
Script end

Main resources:

Total runtime0.5716 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 593.9922152.6250
Module start 'layout' 0.00550.0024 746.617239.4453
Module start 'content' 0.00790.5623 786.0625543.7891
Module end 'content' 0.57030.0013 1,329.851612.1563
Script end 0.5716  1,342.0078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.5017160.0002
Check MTime0.00120.2053160.0001
Mysql Total
Database connection0.00070.116710.0007
Mysqli_queries0.527592.2829540.0098
Looping result0.00050.0803520.0000
Template Total0.548295.920.2741
Template load0.00190.340320.0010
Template processing0.546295.558620.2731
Template load and register function0.00010.018210.0001
states
state_id_array0.00030.045310.0003
state_identifier_array0.00090.158320.0005
Override
Cache load0.00160.2837220.0001
Sytem overhead
Fetch class attribute can translate value0.00040.076820.0002
Fetch class attribute name0.00100.182340.0003
XML
Image XML parsing0.00100.174620.0005
class_abstraction
Instantiating content class attribute0.00000.001540.0000
General
dbfile0.00080.1347220.0000
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs