1

I'm trying to load some .csv file from remote servers (so I have to deal with domain problem), and I'm using jsonp with the following code

sql="a csv file link"

$.ajax({
url:sql,
dataType:'jsonp',
}).done(function(){
    console.log("done");
}).error(function(){
console.log("err");
}).fail(function(){
console.log("fail");
}).success(function(){
console.log("success");
});

Some how, this piece of code gives me 2 different result.

1) On certain csv file links, it seems to be getting the complete csv file. However, there is an error saying that the csv file has a "syntax error", and .error and .fail is executed.

2) On some other csv file links (something like.http:// host.com:port/file.csv? select from table), somehow nothing happens. The .done/.success are not called, nor the .fail/.error are called

Can anyone tell me the solution or possible causes of those above problems?

Thanks!

user1948847
  • 955
  • 1
  • 12
  • 27

1 Answers1

1

If the remore server allows JSONP, use something like the following:

sql="a csv file link"+"?callback=myFunc";

Where myFunc is a user defined function to process the data from the remote server.

Another technique is to use a proxy as described here: https://stackoverflow.com/a/2559062/1186628

[Update]

here is a very simple example of what myFunc might look like:

function myFunc(data){
     alert(data);
}
Community
  • 1
  • 1
mohamed elbou
  • 1,829
  • 1
  • 18
  • 21