Forums / Developer / problem with ajax and ez publish

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

eZ debug

Timing: Jan 18 2025 11:11:44
Script start
Timing: Jan 18 2025 11:11:44
Module start 'content'
Timing: Jan 18 2025 11:11:45
Module end 'content'
Timing: Jan 18 2025 11:11:46
Script end

Main resources:

Total runtime1.8264 sec
Peak memory usage4,096.0000 KB
Database Queries191

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 588.8359180.8281
Module start 'content' 0.00661.5454 769.6641548.8672
Module end 'content' 1.55210.2743 1,318.5313336.7422
Script end 1.8263  1,655.2734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.2356210.0002
Check MTime0.00180.0976210.0001
Mysql Total
Database connection0.00080.042610.0008
Mysqli_queries1.746195.60551910.0091
Looping result0.00250.13611890.0000
Template Total1.790398.020.8952
Template load0.00200.107720.0010
Template processing1.788397.914120.8941
Template load and register function0.00010.004510.0001
states
state_id_array0.00120.067310.0012
state_identifier_array0.00190.103320.0009
Override
Cache load0.00160.0896220.0001
Sytem overhead
Fetch class attribute can translate value0.00180.097630.0006
Fetch class attribute name0.00110.060740.0003
XML
Image XML parsing0.00130.072930.0004
class_abstraction
Instantiating content class attribute0.00000.000340.0000
General
dbfile0.00330.1780330.0001
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs