W
W
wcoder2012-03-11 20:26:06
JavaScript
wcoder, 2012-03-11 20:26:06

jQuery Ajax, please give me CSV?

I'm interested in the question - is it possible to get CSV from another domain / site using jQuery, in my case Yahoo Finance

PS JSONP - it requests data, but when parsing the data it gives an error, obviously due to the fact that it does not receive JSON.

$.ajax({<br>
      url: 'http://finance.yahoo.com/d/quotes.csv?s=AAPL&f=bcll2l3nosx',<br>
      success: function (resp) {<br>
        console.log(resp);<br>
      },<br>
      error: function(e){<br>
        console.log('Error!');<br>
      },<br>
      dataType: 'jsonp'<br>
});<br>
<br>
В консоли хрома вижу: Uncaught SyntaxError: Unexpected token ,<br>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2012-03-12
@wcoder

1. You can’t use frames, then you won’t be able to take text from them if they are from another domain
2. You can’t use JSONP, it requires a valid JS response, but there isn’t one
3. You can’t use regular Ajax, the browser will not allow you to make a request.
You can make a service that will take csv from Yahoo, translate it into JSON and send it using JSONP. This is the only option, or find a service that already works with JSONP

A
Anatoly, 2012-03-11
@taliban

In a nutshell, how JSONP works:
1. A request is created, and a script is connected with the address that you call.
2. The receiving party generates a response like yourCallbackFunction(<valid javascript params>)
2.a The jQuery callback does everything itself.
2.b pay attention to <valid javascript params>
3.!!!
4. PROFIT
Conclusion:
1. To use JSONP, the server side must know that you want it and must be ready for this
2. The server side must return a valid code
3. Uncaught SyntaxError: Unexpected token, this means that the JS interpreter is not ready for a comma in this place, but it is there, because: 544.57,"+3.18 - +0.59%",… Not valid JS code

M
Max Kuznetsov, 2012-03-11
@pluseg

Try to pick up csv in plain text, and then use some kind of plug-in. For example, code.google.com/p/js-tables/wiki/CSV or any other .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question