3
I have the following code on my website.
setInterval(function(){
var id = $("#id_radio").val();
var id_glob;
$.ajax({
type: "POST",
url: "ajax/update_radio.php",
data: "id="+id,
success:function(e){
$("#nome_radio").removeClass("ellipsis");
$("#hora_radio").removeClass("ellipsis");
if(e!==""){
var expl = e.split(",");
var id_glob = expl[3];
if(expl[3] !== id){
$("#img_radio").animate({
opacity: 0
}, 300);
setTimeout(function(){
$("#img_radio").attr("src", "radio/programas/"+expl[3]+"/"+expl[0]);
$("#img_radio").css("width", "100%");
}, 300)
setTimeout(function(){
$("#img_radio").animate({
opacity: 1
}, 300);
}, 300)
$("#nome_radio").html(expl[1]);
$(".programa_radio").html(expl[1]);
$(".horario_radio").html(expl[2]);
$("#hora_radio").html(expl[2]);
$("#id_radio").val(expl[3]);
$("#pub_radio").animate({
opacity: 0
}, 300);
setTimeout(function(){
$("#pub_radio").attr("src", "adm/images/publicidades/"+expl[5]+"/"+expl[6]);
$("#pub_radio").css("max-width", "100%");
}, 300)
setTimeout(function(){
$("#pub_radio").animate({
opacity: 1
}, 300);
}, 300)
$.ajax({
type: "POST",
url: "ajax/update_pub_radio.php",
data: "id="+$("#id_radio").val(),
success: function(t){
$(".carousel_imgs").animate({
opacity: 0
}, 300);
setTimeout(function(){
$(".carousel_imgs").html(t);
}, 300)
setTimeout(function(){
$(".carousel_imgs").animate({
opacity: 1
}, 300);
}, 300)
}
})
}
}
}
});
}, 1000);
With this code he updates the current radio program every second but after a while an error starts to appear on the console (403 Forbidden). I have the exact same code on another website and it works perfectly.
And besides giving 403 error on the console, the whole site gets Forbidden 403 until after a few seconds.
Something’s wrong with me?
Look at the guy
POST
you are trying to send a type variableGET
,"id="+id
. If you intend to send via post try to send so:data: { id: id }
, don’t forget thedataType: 'json'
– adventistaam
It has nothing to do with the code Javascript. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
– Valdeir Psr
@Valdeirpsr But the request is made through this code so there must be something I can do.
– I_like_trains
@I_like_trains Already tried to simulate requests with Curl or Postman and ascertain the outcome?
– Valdeir Psr
@Valdeirpsr No, you can create an example of how to do it?
– I_like_trains
I made a
.sh
basic good (and not tested) https://hastebin.com/jihalutuha.bash– Valdeir Psr
You are sending a request every second to the server, even if you do not receive the reply you send another one right away. Maybe it’s best to change the way you update the data. What can happen is you are filling the server with requests and after a while it "hangs". Believe me, even being light data has server that is worth nothing.
– Henrique Pauli