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.

asked Jan 4, 2013 at 15:10
6
  • 1
    I had similar issue sometime back.. Check stackoverflow.com/questions/12611469/… Commented Jan 4, 2013 at 15:12
  • 2
    Enable CORS on the server with your dataset. Commented Jan 4, 2013 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). Commented Jan 4, 2013 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. Commented Jan 4, 2013 at 15:16
  • Thank you guys! I don't want to use YQL and CORS so i need to write a proxy-script right? Commented Jan 4, 2013 at 15:17

1 Answer 1

1

You have following options:

  1. Use server side proxy
  2. JSONP, wrap csv into jsonp response
  3. Use CORS (check cross browser support)
answered Jan 4, 2013 at 15:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.