Su una risposta get
ho content-disposition: attachment;filename=f.csv
e ho bisogno di scaricare contenuto di questo file nella pagina.
Su richiesta $.ajax
Ho un errore. Come posso ottenere il contenuto del file utilizzando jQuery ajax
(o get
)?
UPDCome ottenere il contenuto del file allegato con jQuery
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
}
ottenere
Object {
...
readyState 0
responseText ""
status 0
statusText "error"
}, error,
UPD 2
ho trovato un plugin jquery.fileDownload, ma mostra la finestra del browser con Salva o aperto dialogo, in questo modo:
Ma ho bisogno di ottenere il contenuto del file .
Non è necessario scaricare il file sul computer.
UPD 3
completa Codice:
$.ajax({
url: link,
crossDomain: true,
dataType: "text",
success: function(data, textStatus, jqXHR) {
alert(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
}
});
File genera da un altro servizio e non posso cambiarlo.
UPD 4
Prima di tutto I'l cercare di ottenere i dati json
da un altro dominio in questo modo:
$.ajax({
url: link,
async: true,
cache: true,
dataType: "jsonp",
crossDomain: true,
type: "GET",
jsonp: "finance_charts_json_callback",
jsonpCallback: "finance_charts_json_callback",
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
},
success: function(data, textStatus, jqXHR) {
console.log(data);
}
});
link
sembra http://chartapi.finance.yahoo.com/instrument/1.0/a/chartdata;type=quote;ys=2012;yz=2;ts=1234567890/json?finance_charts_json_callback=finance_charts_json_callback
Ed è intestazioni di risposta:
HTTP/1.1 200 OK
Date: Wed, 30 Apr 2014 12:01:08 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO ... GOV"
Cache-Control: public
Expires: Thu, 01 May 2014 00:32:18 GMT
Last-Modified: Wed, 30 Apr 2014 00:32:18 GMT
Content-Type: text/javascript; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding,X-Ssl
Age: 0
Via: http/1.1 yts39.global.media.ir2.yahoo.com (...)
Server: ATS
Connection: keep-alive
Tutto funziona bene.
Quando provo ad ottenere il file da un altro server lì è intestazioni di risposta:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Wed, 30 Apr 2014 12:09:01 GMT
Pragma: no-cache
Content-Type: text/csv
Expires: -1
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
content-disposition: attachment;filename=export.csv
Content-Encoding: gzip
Vary: Accept-Encoding
E qual è questo errore? –
@ t.niese vedere ** UPD ** sezione – ostapische
possibile duplicato di http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax – setec