简体   繁体   中英

How can i do cross domain query using ajax & jsonp?

I send ajax to url , but i get error. Here is my code:

$.ajax({
    url: "http://webrates.truefx.com/rates/connect.html?q=ozrates&c=EUR/USD&f=csv&s=n",
    dataType : 'jsonp',
    success: function (data) {
        alert(data);
    }
})

Maybe i doing something wrong?

In order to access data using JSONP, the server you are requesting the data from must format its response as JSONP.

You are getting an error because the response is not JSONP (it is CSV, which you asked for explicitly when you put t=csv in the query string).

Either:

  • Use a different method to get the data
  • Change the server so it responds with JSONP formatted data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM