How to call a PHP function via onClick.
How to call a PHP function via onClick.
dinobernal
Posts: 6Questions: 0Answers: 0
Is it possible to call a PHP function via click()? Below is a portion of the code.
jQuery(document).ready(function() {
var oTable = jQuery('#syslog-list').dataTable({
bProcessing: true,
sAjaxSource: '%getUrl',
bJQueryUI: true,
sPaginationType: 'full_numbers',
iDisplayLength: 100,
bFilter: true,
bAutoWidth: false,
bProcessing: true,
bServerSide: true,
bFilter: true,
aoColumns: [
{sWidth: '160px', bSearchable: false, bSortable: false},
{bSearchable: true, bSortable: false}
],
fnFilter: function(value, index) {
},
fnServerData: function ( url, data, callback ) {
jQuery.ajax({
"url": url,
"data": data,
"success": callback,
"dataType": "json",
"cache": false,
"error": function (xhr) {
if (!xhr || xhr.status != 401) {
alert( "DataTables warning: JSON data from server failed to load or be parsed. "+
"This is most likely to be caused by a JSON formatting error." );
} else {
alert('Your session expired !');
window.location.href = '%loginUrl';
}
}
});
}
});
oTable.fnSetFilteringDelay(400);
oTable.fnFilter('[' + jQuery('#log_date_from').val() + ',' + jQuery('#log_date_to').val() + ']');
$('.dataTables_filter input').keyup(function(){
$('#log_search').val($('.dataTables_filter input').val());
});
jQuery('.dataTables_filter').hide();
jQuery('#log_search_combined').click(function() {
var sFilter = '[' + jQuery('#log_date_from').val() + ',' + jQuery('#log_date_to').val() + '] ';
if (jQuery('#fromhost').val()) {
sFilter = sFilter + 'FROMHOST="' + jQuery('#fromhost').val() + '"';
}
if (jQuery('#syslogtag').val()) {
sFilter = sFilter + ' SYSLOGTAG="' + jQuery('#syslogtag').val() + '"';
}
if (jQuery('#searchstring').val()) {
sFilter = sFilter + ' MESSAGE="' + jQuery('#searchstring').val() + '"';
}
oTable.fnFilter(sFilter);
$('#log_search').val($('.dataTables_filter input').val());
});
});
=============================
I'm trying to add a click() function that will call a PHP function that will process the current filtered data and output it to a file.
jQuery(document).ready(function() {
var oTable = jQuery('#syslog-list').dataTable({
bProcessing: true,
sAjaxSource: '%getUrl',
bJQueryUI: true,
sPaginationType: 'full_numbers',
iDisplayLength: 100,
bFilter: true,
bAutoWidth: false,
bProcessing: true,
bServerSide: true,
bFilter: true,
aoColumns: [
{sWidth: '160px', bSearchable: false, bSortable: false},
{bSearchable: true, bSortable: false}
],
fnFilter: function(value, index) {
},
fnServerData: function ( url, data, callback ) {
jQuery.ajax({
"url": url,
"data": data,
"success": callback,
"dataType": "json",
"cache": false,
"error": function (xhr) {
if (!xhr || xhr.status != 401) {
alert( "DataTables warning: JSON data from server failed to load or be parsed. "+
"This is most likely to be caused by a JSON formatting error." );
} else {
alert('Your session expired !');
window.location.href = '%loginUrl';
}
}
});
}
});
oTable.fnSetFilteringDelay(400);
oTable.fnFilter('[' + jQuery('#log_date_from').val() + ',' + jQuery('#log_date_to').val() + ']');
$('.dataTables_filter input').keyup(function(){
$('#log_search').val($('.dataTables_filter input').val());
});
jQuery('.dataTables_filter').hide();
jQuery('#log_search_combined').click(function() {
var sFilter = '[' + jQuery('#log_date_from').val() + ',' + jQuery('#log_date_to').val() + '] ';
if (jQuery('#fromhost').val()) {
sFilter = sFilter + 'FROMHOST="' + jQuery('#fromhost').val() + '"';
}
if (jQuery('#syslogtag').val()) {
sFilter = sFilter + ' SYSLOGTAG="' + jQuery('#syslogtag').val() + '"';
}
if (jQuery('#searchstring').val()) {
sFilter = sFilter + ' MESSAGE="' + jQuery('#searchstring').val() + '"';
}
oTable.fnFilter(sFilter);
$('#log_search').val($('.dataTables_filter input').val());
});
});
=============================
I'm trying to add a click() function that will call a PHP function that will process the current filtered data and output it to a file.
This discussion has been closed.
Replies
Problem I have there is when I do this, I can't prompt for the output filename (and target directory).
[code]
$.ajax( sUrl, {
//url: sUrl, // you can put the url here and skip it in the first parameter.. same thing)
data: aData, // array of data (parameters), or string formatted as querystring
dataType: "json", // xml, json, script, or html
async: false, // if you want this to run asynchronously or not. default true
error: function (jqXHR, textStatus, errorThrown) { }, // what to do in case of error
success: function (data, textStatus, jqXHR) { } // what to do on success
});
[/code]
http://api.jquery.com/jQuery.ajax/
Does this mean that in the ajax call, I can prompt for where to save the file on my computer and not on the server? Because it is a report file.
http://stackoverflow.com/questions/445774/correct-way-to-trigger-a-file-download-in-php
Basically the author sets up an iframe and triggers the HTTP download on the iframe. I suppose iframe could be invisible.