I have a problem with my Ajax application.
Here is the way it works:
the user interface page (asp) send a request via a XMLHttpRequest object to an asp page which connect to a database, transform the resultset to XML parse it with a XSLT file and send the resulting HTML code back to the user interface page in the DOM of which it is inserted using the innerHTML property.
This works perfectly... Except when the XSLT generates a javascript function. Indeed when I try to call this generated function (through click or blur or other event), i get an error saying that the function is not defined...
I have googled as i could to find a solution but could not find any... does anybody has any idea ?
the XML schema is of the form used by mysql:
<resultset>
<row>
<field name="column_name"></field>
</row>
<resultset>
below is the XSLT code:
Code : Tout sélectionner
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" omit-xml-declaration="yes" standalone="yes" indent="yes"/>
<xsl:template match="resultset">
<script type="text/javascript"><![CDATA[
function searchAndDisplay(){
var whereClause = '';
]]><xsl:for-each select="row"><![CDATA[
if(document.getElementById("chbx_" + ]]><xsl:value-of select="field[@name='id_group']"/><![CDATA[).checked == true){
if(whereClause != ''){
whereClause += ' OR id_group = ' + ]]><xsl:value-of select="field[@name='id_group']"/><![CDATA[;
}
else{
whereClause = 'where ( id_group = ' + ]]><xsl:value-of select="field[@name='id_group']"/><![CDATA[;
}
}
]]></xsl:for-each><![CDATA[
var keyword_value = document.getElementById('group_keyword').value;
if(keyword_value != ''){
if(whereClause != ''){
whereClause += ") AND (description LIKE '";
var akeywords = keyword_value.split(" ");
var i;
for( i = 0; i < akeywords.length ; i++){
whereClause += '\%' + akeywords[i] ;
}
whereClause += "\%')";
}
else{
whereClause = "where (description LIKE '";
var akeywords = keyword_value.split(" ");
var i;
for( i = 0; i < akeywords.length; i++){
whereClause += '\%' + akeywords[i] ;
}
whereClause += "\%')";
}
}
else{
if(whereClause != ''){
whereClause += ');';
}
}
alert(whereClause);
//getAndRenderXML('select * from t_team ' + whereClause, '/teams/xslt/list_teams.xslt', document.getElementById('viewPort'), '', undefined)
}
]]></script>
<form name="group_form" id="group_form">
<p>Select a group:</p>
<p>
<xsl:for-each select="row">
<xsl:sort select="field[@name='name']"/>
<input type="checkbox" name="chbx_{field[@name='id_group']}" id="chbx_{field[@name='id_group']}" value="{field[@name='id_group']}"/>
<label for="chbx_{field[@name='id_group']}">
<xsl:value-of select="field[@name='name']"/>
</label>
<br/>
</xsl:for-each>
</p>
<p>
<label for="group_keyword">Keyword</label>
<br/>
<input type="text" id="group_keyword" name="group_keyword"/>
<br/>
</p>
<a href="Javascript:;" onclick="javascript:searchAndDisplay()">Get corresponding teams</a>
</form>
</xsl:template>
</xsl:stylesheet>
THX
Nicolas