On a get
response I have content-disposition: attachment;filename=f.csv
and I need to download content of this file on the page .
On a $.ajax
request I have an error.
How can I get content of file using jQuery ajax
(or get
)?
UPD
error: function( jqXHR, textStatus, errorThrown ) {
console.log( jqXHR, textStatus, errorThrown );
}
get
Object {
...
readyState 0
responseText ""
status 0
statusText "error"
}, error,
UPD 2
I found a jquery.fileDownload plugin, but it shows browser's window with save or open dialog, like this:
But I need to get file content.
I'm no need to download file on computer.
UPD 3
Full code listing:
$.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 generates by another service and I can't change it.
UPD 4
First of all I'l try to get json
data from another domain like this:
$.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
looks like 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
And it's response headers:
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
All works fine.
When I try to get file from another server there it's response headers:
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