मैं AJAX के लिए बिल्कुल नया हूं। मैं AJAX का उपयोग कर सर्वर पर एक अनुरोध भेज रहा हूँ। सेवा एक पाठ फ़ाइल देता है। लेकिन डेटा लौटाए जाने पर कोई डाउनलोड बॉक्स नहीं दिखाई देता है। बाकी सेवा है कि फाइल रिटर्न इस प्रकार है: इस प्रकारअजाक्स कॉल को रीस्टफुल सेवा से लौटाई गई फ़ाइल डाउनलोड करने के लिए कॉल करें
@Path("/examples")
public class ExampleCodesRest {
@POST
@Path("/getcode")
@Produces(MediaType.TEXT_PLAIN)
public Response getCodes(@Context ServletContext context){
String in=context.getRealPath("/WEB-INF/reports.jrxml");
File file=new File(in);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=\"file_from_server.log\"");
return response.build();
}
}
मेरे AJAX कॉल है:
$('a#link').click(function(event){
event.preventDefault();
$.ajax({
url: '/reports/rest/examples/getcode',
type: 'POST'
});
});
फ़ाइल AJAX के बिना सफल डाउनलोड करता है। AJAX के साथ, यह फ़ाइल डाउनलोड नहीं करता है। कृपया सलाह दें।
[एजेक्स पोस्ट से हैंडल फ़ाइल डाउनलोड] के संभावित डुप्लिकेट (http://stackoverflow.com/a/23797348/148271) – IsmailS