Salut tout le monde, Je reçois quelques valeurs de la page html pour l'impression d'un formulaire et certaines valeurs de API, tandis que les boutons d'impression clique j'appelle la fonction d'impression, dans cette fonction d'impression je suis appeler les valeurs de l'API trop en utilisant AJAX, avec des valeurs ajax forment pas l'impression bcoz api prendre le temps de charger la base de données, puis je l'ai écrit la fonction d'impression à l'intérieur du ajax succès ici aussi ne fonctionne pas quelqu'un peut-il s'il vous plaît me aider ..Retour une autre fonction sur Ajax succès
function myFunction() {
var jobcard_id=document.getElementById('jobcard_id').value;
var vehicle_num1=document.getElementById('veh-numbr1').value;
var vehicle_num2=document.getElementById('veh-numbr2').value;
var vehicle_num3=document.getElementById('veh-numbr3').value;
var vehicle_num4=document.getElementById('veh-numbr4').value;
var vehicle_number=vehicle_num1+" "+vehicle_num2+" "+vehicle_num3+" "+vehicle_num4;
var cust_name=document.getElementById('cust_name').value;
var cont_num=document.getElementById('cont_num').value;
var cont_addr=document.getElementById('cont_addr').value;
var brand=document.getElementById('brand').value;
var model=document.getElementById('model').value;
var kms=document.getElementById('kms').value;
var toolkit_availability=document.getElementById('toolkit_availability').value;
if(toolkit_availability == "True"){ var tol_kit= 'Yes';}else{var tol_kit='No';}
var fuel_percentage=document.getElementById('fuel_percentage').value;
//var customer_complaint=document.getElementById('customer-complaint').value;
var serviceType=document.getElementById('serviceType').value;
var delivery_time=document.getElementById('delivery-time').value;
var mechanic_name=document.getElementById('mechanic_name').value;
var total_estimation=document.getElementById('total-estimation').value;
$.ajax({
url: "/dealer/details",
dataType : 'json',
success: function(data) {
//called when successful
//alert(data[0].sunday);
alert(data.address);
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>Jobcard</title>');
printWindow.document.write('</head><body ><br><h3 style="text-
align:center;"></h3><br><hr><br>');
printWindow.document.write('<h4 style="text-align:center;">Invoice Number: '+jobcard_id+'</h4>');
printWindow.document.write("<table>");
printWindow.document.write("<tr><td style='width:300px;'><b><h2>Customer Details:</h2></b></td><td style='width:300px;'></td><td style='width:300px;'><b><h2>Vehicle Details:</h2></b></td></tr>");
printWindow.document.write("<tr><td style='width:300px;'>Vehicle Number: "+vehicle_number+"</td><td style='width:300px;'></td><td style='width:300px;'>Brand : "+brand+"</td></tr>");
printWindow.document.write("<tr><td style='width:300px;'>Name: "+cust_name+"</td><td style='width:300px;'></td><td style='width:300px;'>Model : "+brand+"</h2></td></tr>");
printWindow.document.write("<tr><td style='width:300px;'>Contact Number: "+cont_num+"</td><td style='width:300px;'></td><td style='width:300px;'>Kilometers: "+kms+"</td></tr>");
printWindow.document.write("<tr><td style='width:300px;'>Address: "+cont_addr+"</td><td style='width:300px;'></td><td style='width:300px;'>Toolkit: "+tol_kit+"</td></tr>");
printWindow.document.write("<tr><td style='width:300px;'></td><td style='width:300px;'></td><td style='width:300px;'>Fuel Percentage: "+fuel_percentage+"</td></tr>");
printWindow.document.write("<tr><td><br><br></td></tr>");
printWindow.document.write("</table><br><table cellpadding='20' cellspacing='20' border='1' style='border-collapse:collapse;'>");
printWindow.document.write("<tr><th>SERIVICE TYPE</th><th>CUSTOMER COMPLAINTS</th><th>MECHANIC NAME</th></tr>");
printWindow.document.write("<tr><td>"+serviceType+"</td><td>"+customer_complaint+"</td><td>"+mechanic_name+"</td></tr>");
printWindow.document.write("</table><br><br><br>Estimated Delivery Time: "+delivery_time+"<br><br>Estimated Price: "+total_estimation+" INR<br><br><br><br><br><Br><hr>");
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
},
error: function(e) {
//called when there is an error
console.log(e.message);
}
});
}
Avez-vous essayé à la place de changer la fonction 'myFunction() {};' pour var myFunction = {} 'et ensuite de transférer la valeur de la variable à AJAX? Vous avez oublié quelque chose aussi spécifiez la méthode 'type:" POST "d'entrée dans votre AJAX – Gabriel