Download file using Ajax

Dapet ilmu baru lagi nih gaess 😀
Yaa kalo kalian udah tau sih mungkin ini keliatan biasa aja tapi karna saya baru tau dan baru bisa ini berasa wah bangat dah :p , heheee.

Okeh langusng aja dicoba scriptnya :

//Ajax Download

$(document).on("submit", "form.fileDownloadForm", function (e) {
     var nim = $('#nim').val();
     var nama = $('#nama').val();
     var sms = $('#nama').val();
     var prodi = $('#prodi').val();
     var tahunid = $('#tahunid').val();
 	
     $.fileDownload($(this).prop('action'), {
// 	preparingMessageHtml: "We are preparing your report, please wait...",
 	failMessageHtml: "Maaf, terdapat gangguan dalam pemrosesan data. Silahkan coba lagi.",
 	httpMethod: "POST",
 	data:{
 			nim: nim,
 			nama: nama,
 			prodi: prodi,
 			tahun: tahunid
 		}
     });
     e.preventDefault(); //otherwise a normal form submit would occur
});

Sebelum execute di aplikasinya download dulu pluginnya dibawah ini.

jQuery.download source : https://raw.githubusercontent.com/johnculviner/jquery.fileDownload/master/src/Scripts/jquery.fileDownload.js

Advertisements
This entry was posted in php and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s