1

There's a CSV file uploaded to the server that I want to parse using javascript/jquery.

I'm trying to get the file using ajax call but it's always giving me error.:

XMLHttpRequest cannot load https://1fichier.com/?w5hfqz60tk&_=1474818392318. No 'Access-Control-Allow-Origin' header is present on the requested resource.

$.ajax({
        url:'https://1fichier.com/?w5hfqz60tk',
        type: "GET",
        dataType: "text",

        success: function (data){
          parseFile(data);

        },
        error:function(e){

        }
    });

I need to run the above code in jsFiddle.. How can I bypass this error?

Or is there any alternative way to download a file?

Update: I just found out that adding url like this: https://crossorigin.me/MY_HTTP(S)_LINK solved my problem but I'm looking for an authentic way.

5
  • Hit F12 and look at the error in the console. Likely cross origin error Commented Sep 25, 2016 at 15:44
  • can you share the console errors? Commented Sep 25, 2016 at 15:45
  • You should at least console.dir(e) in your error function Commented Sep 25, 2016 at 15:46
  • error mentioned in the Q Commented Sep 25, 2016 at 15:49
  • "How can I bypass this error?" You can try using YQL Commented Sep 25, 2016 at 15:54

1 Answer 1

2

How can I bypass this error? Or is there any alternative way to download a file?

You can use $.getJSON(), YQL

var url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'https%3A%2F%2F1fichier.com%2F%3Fw5hfqz60tk'%0A&format=json&callback="

$.getJSON(url, function(data) {
  console.log(data.query.results)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.