1
私はcodeigniterでWebサイトを開発しており、ファイルをダウンロードする機能があります。 私の問題は、ユーザーが任意のドキュメントをダウンロードしたときに、レコードをデータベースに挿入してダウンロード履歴を保持するという記録を残したいということです。 私はそのボタンのクリックでjquery ajaxを呼び出し、href属性ではダウンロードの機能を呼び出しました。 私は最初にjquery関数を呼び出す方法を教えてください私はダウンロード機能をクリックした後、ダウンロードが完了した後。 が、これはこれはこれは私が前に呼び出したいアヤックスでアヤックスダウンロード機能を呼び出す前にajax関数を呼び出す
$(".link").click(function(){
var id=$(this).data("data1");
$.ajax({
type : 'POST',
url : '<?php echo base_url();?>index.php/Faculty_controller/get_all_bmaterial',
data : { 'id' : id },
success : function(data)
{
$(".tbl").html("");
recs=$.parseJSON(data);
head='<tr><td>Sr. No</td><td align=center><br><h4>Material Name</td><td colspan="2"><center>Action</center></td></tr>';
$(".tbl").append(head);
$.each(recs,function(i,v)
{
a=i+1;
r='<tr><td><br><center>'+a+'</td><td><br>'+v.file_name+'</td><td><br><center><a class="dwnld btn btnd btn-danger" href="<?php echo base_url();?>index.php/Student_controller/download_bachelor_material/'+v.file_name+'"/"'+v.materialno+'" data-data1='+v.materialno+' data-data2='+v.file_name+' data-content="Download this material" data-placement="bottom" data-trigger="hover"><i class="fa fa-download"></i></a></td></tr>';
$(".tbl").append(r);
$('a').tooltip({ });
});//end of foreach
}//end of success
});//end of ajax
});//end of link click function
を使用してダウンロードするためのリンクを作成するために、ビューにあるダウンロード
public function download_b_question_paper($fileName = NULL)
{
$this->load->helper('download'); //load helper
if ($fileName)
{
$file = realpath ("b_question") . "\\" . $fileName;
if (file_exists ($file))// check file exists
{
$data = file_get_contents($file);// get file content
force_download ($fileName, $data);//force download
}
}
}
の私のコードで事前
でお願いしますダウンロード機能が呼び出されました
$("a").click(function(){
alert('hello');
$.ajax({
type : 'POST',
data : { 'subkey' : id },
url : "<?php echo base_url()?>index.php/Studnet_Controller/b_mat_activity",
success : function(data)
{
alert('hello');
}
});
});