0

I want to make a cross-domain request with ajax to get non-JSON(!) data (CSV-File). I'm using following code:

$.ajax({
      "url": dataset.url,
      "dataType": "text",
      "crossDomain": true
    }).done(function(data) {

      });

But it is not working because of the cross-domain restriction. When i set the datatype to "jsonp", it's also not working because the data will be interpreted and i get syntax errors.

Are there any workarounds? Thanks.

devOp
  • 3,150
  • 1
  • 18
  • 32
  • 1
    I had similar issue sometime back.. Check http://stackoverflow.com/questions/12611469/get-list-of-jquery-ui-themes-from-an-url-same-origin-policy – Selvakumar Arumugam Jan 04 '13 at 15:12
  • 2
    Enable [CORS](http://enable-cors.org) on the server with your dataset. – Sirko Jan 04 '13 at 15:12
  • 1
    You can either wrap the csv data into a jsonp response on the other domain's server or make your get to a script on your server that simply get and return the csv data (kind of proxy). – yent Jan 04 '13 at 15:13
  • 1
    You can use CORS, but keep in mind that support for it is lacking with IE. IE7 doesn't support it at all, and IE8-10 you'll have to handle the request yourself (no `$.ajax` unless you extend it) because IE uses a different xhr object for CORS requests. Best would be to just make the request from your server. – Kevin B Jan 04 '13 at 15:16
  • Thank you guys! I don't want to use YQL and CORS so i need to write a proxy-script right? – devOp Jan 04 '13 at 15:17
  • Right, that would be the only other option. – Kevin B Jan 04 '13 at 15:19

1 Answers1

1

You have following options:

  1. Use server side proxy
  2. JSONP, wrap csv into jsonp response
  3. Use CORS (check cross browser support)
Gurpreet Singh
  • 20,907
  • 5
  • 44
  • 60