Having a problem with using a function in my dynamic accordion divs.
$(document).ready(function ()
{
$.ajax(
{
url: "accordion-query.php",
dataType: "json",
success: function (data)
{
var accord='';
$.each( data, function( index, item)
{
var courseCode = item.Course_Code;
accord += '<h3>'+item.Course_Name+' - '+item.Course_Code+'</h3><div>'+createTable(courseCode)+'</div>';
});
$( "#accordion" ).html( accord );
$( "#accordion" ).accordion();
}
});
});
The createTable(code) {}
function inside the accordion divs is not working
function createTable(code)
function createTable(code)
{
$.ajax(
{
url: "staff-query.php",
data: "q=" + code,
dataType: "json",
success: function (data)
{
$.each( data, function( index, item)
{
tabletext += '<tr><td>'+item.B_Code+'</td><td>'+item.Surname+', '+item.FirstName+'</td><td>'+item.Email+'</td><td>'+item.Course_Name+'</td><td>'+item.Mod_Title+'</td><td>'+item.Title+'</td><td>'+item.Uploaded+'</td><td>'+item.ViewedDate+'</td><td>'+item.Comments+'</td></tr>';
});
}
return tabletext;
});
}
The accordion-query.php
and staff-query.php
are both returning what i want them to, json encoded arrays with the correct data in them, but it wont pass through to the table.
When I change the function to something simple like...
function createTable(code)
{
return code;
}
...it puts the correct data into the div and displays all the accordion tabs properly. I cannot see the issue with the function. The document.ready {}
and the createTable()
are both in the header, I have tried moving them to after the body and all other combinations. I havent shown the <table><tr><th>
opening and closing tags so as not to clutter up the code, but that is not the problem either as I have tried and tested it.