I've made a function with an ajax post. This function is in an external js file on my server. (functions.js).
From another page I call the function like this:
$('table.table_sort td').click(function(e)
{
var url = "https://<?=$_conf['siteurl']?>/files/process.ajax.php";
sortTable(url, e);
});
The function in the functions.js looks like this:
function sortTable(url, e)
{
if( !$(e.target).is(".last, .last input")){
$('input[name="sort"]').parent('td').removeClass('sort_active');
$('input[name="sort"]').parents('td').children('div').removeClass().addClass('sort_none');
if($(this).children('input[type="radio"]:first').is(':checked'))
{
$(this).children('input[type="radio"]:last').prop('checked', true);
$(this).children('div').removeClass().addClass('sort_asc');
$('input[name="sort"]:checked').parent('td').addClass('sort_active');
}
else
{
$(this).children('input[type="radio"]:first').prop('checked', true);
$(this).children('div').removeClass().addClass('sort_desc');
$('input[name="sort"]:checked').parent('td').addClass('sort_active');
}
$.ajax({
type: "POST",
url: url,
async: false,
data: $('#myform').serialize(),
complete: function(data)
{
$('#results').html(data.responseText);
}
});
}
}
Unfortunately nothing happened. When I do this it work:
$('table.table_sort td').click(function(e)
{
var url = "https://<?=$_conf['siteurl']?>/files/process.ajax.php";
if( !$(e.target).is(".last, .last input")){
$('input[name="sort"]').parent('td').removeClass('sort_active');
$('input[name="sort"]').parents('td').children('div').removeClass().addClass('sort_none');
if($(this).children('input[type="radio"]:first').is(':checked'))
{
$(this).children('input[type="radio"]:last').prop('checked', true);
$(this).children('div').removeClass().addClass('sort_asc');
$('input[name="sort"]:checked').parent('td').addClass('sort_active');
}
else
{
$(this).children('input[type="radio"]:first').prop('checked', true);
$(this).children('div').removeClass().addClass('sort_desc');
$('input[name="sort"]:checked').parent('td').addClass('sort_active');
}
$.ajax({
type: "POST",
url: url,
async: false,
data: $('#myform').serialize(),
complete: function(data)
{
$('#results').html(data.responseText);
}
});
}
});
Any ideas?