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!

1 Answer 1

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

umm, could you give an example of the myFunc?? Really appreciated :)

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.