In my jQuery function, the items in each table row are downloaded via the following method. Instead of working on each line, the color change command made in the success section works after all processes are finished. What should I do to make it work after each download? I think this is due to Thread.Sleep (1000). but the site where I downloaded the file wants 1 second between each request.
here is my qjuery function
$.each($("tr[class='sec']"), function () {
if ($(this).children('td:eq(1)').children("input[type='checkbox']").prop('checked')) {
durum = $(this);
var beyan = {};
var secililer = [];
beyan.Id = $(this).attr("id");
beyan.TahakkukId = $(this).data("id");
beyan.KisaKod = $(this).children('td:eq(2)').html();
beyan.BeyannameTuru = $(this).children('td:eq(4)').html();
beyan.Ay = $(this).children('td:eq(5)').html().substring(8, 10);
beyan.Yil = $(this).children('td:eq(5)').html().substring(11, 16);
secililer.push(beyan);
$.ajax({
url: '/Ebeyan/BelgeAl',
type: "POST",
dataType: "text",
async: false,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ secililer, islemler, token, }),
success: function (data) {
Indirildi(durum);
}
});
}
});
function Indirildi(gelen) {
gelen.css('background-color', 'green');
gelen.children('td:eq(8)').html("İndirildi");
}
here is posted controller
public async Task<string> BelgeAl(List<Beyanname> secililer, List<Islem> islemler, string token)
{
bool indir = true;
bool yazdir = false;
bool gonder = false;
foreach (var islem in islemler)
{
if (islem.IslemTuru == "cbyazdir")
{
yazdir = true;
}
if (islem.IslemTuru == "cbgonder")
{
gonder = true;
}
}
foreach (var GelenBeyan in secililer)
{
string YolAdi = YolHazirla(GelenBeyan);
string DosyaAdi = DosyaAdiHazirla(GelenBeyan);
await dosyaindir(token, YolAdi + "/" + DosyaAdi, "Beyan", GelenBeyan.Id, "");
await dosyaindir(token, YolAdi + "/" + DosyaAdi, "Tahakkuk", GelenBeyan.Id, GelenBeyan.TahakkukId);
}
return "";
}
and here is my download async method
public async System.Threading.Tasks.Task<Boolean> dosyaindir(string token, string yol, string tur, string id, string thkid)
{
string URI = "https://ebeyanname.gib.gov.tr/dispatch?";
string myParameters = "cmd=IMAJ&subcmd=";
if (tur == "Beyan")
{
myParameters += "BEYANNAMEGORUNTULE";
}
else
{
myParameters += "TAHAKKUKGORUNTULE&tahakkukOid=" + thkid;
}
myParameters += "&TOKEN=" + token;
myParameters += "&beyannameOid=" + id;
myParameters += "&inline=true";
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(string.Concat(URI + myParameters));
Req.CookieContainer = Cc;
Req.Method = "GET";
Req.ContentType = "application/pdf;charset=ISO-8859-9";
HttpWebResponse Res = (HttpWebResponse)Req.GetResponse();
Req.KeepAlive = false;
Req.ProtocolVersion = HttpVersion.Version11;
Req.ServicePoint.ConnectionLimit = 1;
Stream dosya = Res.GetResponseStream();
yol += tur + ".pdf";
using (var fs = System.IO.File.Create(yol))
{
dosya.CopyTo(fs);
}
Res.Close();
Req.Abort();
Thread.Sleep(1000);
return true;
}
UPDATE i just now try remove
Thread.Sleep(1000);
and use this function but nothing change
$.each($("tr[class='sec']"), function () {
if ($(this).children('td:eq(1)').children("input[type='checkbox']").prop('checked')) {
durum = $(this);
var beyan = {};
var secililer = [];
setTimeout(function () {
}, 1000);
beyan.Id = $(this).attr("id");
beyan.TahakkukId = $(this).data("id");
beyan.KisaKod = $(this).children('td:eq(2)').html();
beyan.BeyannameTuru = $(this).children('td:eq(4)').html();
beyan.Ay = $(this).children('td:eq(5)').html().substring(8, 10);
beyan.Yil = $(this).children('td:eq(5)').html().substring(11, 16);
secililer.push(beyan);
$.ajax({
url: '/Ebeyan/BelgeAl',
type: "POST",
dataType: "text",
async: false,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ secililer, islemler, token, }),
success: function (data) {
durum.css('background-color', 'green');
durum.children('td:eq(8)').html("İndirildi");
}
});
}
});