0
こんにちは皆、私はフォームを印刷するためのhtmlページとapiからのいくつかの値を取得していますが、印刷ボタンをクリックしている間はprint関数を呼び出しています。あなたは...誰も私を助けてくださいすることができますAjax成功の別の関数を返す
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);
}
});
}
代わりに、 'myFunction(){};を' var myFunction = {} 'に変更して、その変数の値をAJAXに転送しましたか?あなたはAJAXへのエントリの 'type:" POST "'メソッドを指定することも忘れてしまった – Gabriel