1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
$(document).ready(function() {
var prevent = false;
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
$("#site").on("change", function(event){
var csrftoken = getCookie('csrftoken');
// console.log($(this).val());
// console.log($("#site").data("randomization-url"))
// console.log(csrftoken)
$.ajax({
type: "POST",
// url: '{% url "randomization:stock" %}',
url: $("#site").data("randomization-url"),
data: {
// csrfmiddlewaretoken: '{{ csrf_token }}',
csrfmiddlewaretoken: csrftoken,
'site' : $(this).val(),
},
dataType: 'html',
success: function (data) {
// alert(data)
// code html contenant le message d'alerte 'Insufficient stock'
if (data.includes("Insufficient")) {
$("#alerte").html(data);
$("#randomize").children().remove();
}
else {
// alert(data)
$("#alerte").children().remove();
$("#randomize").html(data);
}
}
});
$.ajax({
type: "POST",
url: '/randomization/patients/',
data: {
csrfmiddlewaretoken: csrftoken,
'site' : $(this).val(),
},
dataType: 'html',
success: function (data) {
// alert(data)
$("#patients").children().remove();
$("#patients").html(data);
}
});
});
}); |
Partager