11

My code looks like this. How do I read the response data?

var url = 'http://www.bbc.co.uk/sport/football';

fetch(url, {
  mode : 'no-cors'
}).then(function(response) {
  console.log(response);
});

Response Object

2 Answers 2

14

You can't.

If the origin doesn't support CORS, you can't actually get the response data directly. That's the whole point of no-cors... allowing you to use the response in certain ways, but not actually read/access the data.

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

3 Comments

I changed to jQuery ajax method with jsonp as below var url = 'bbc.co.uk/sport/football?callback=?'; $.ajax({ url: url, method: "GET", dataType: "jsonp", success: function(data) { console.log(data); } }); But getting below error now. Uncaught SyntaxError: Unexpected token < football?callback=jQuery3110607…_1478389724278&_=1478389724279:1
@AnoopMundathan Why would you do that? This URL doesn't support JSON-P, and JSON-P is a nasty hack anyway. You should be using CORS, but since your source doesn't support it, you're out of luck unless you proxy it server-side.
Yes, that option left now. Proxy in server side. Cheers
-5

Use one of below, depending what data you expect:

response.blob()
response.text()
response.formData()
response.json()
response.arrayBuffer()

1 Comment

This is not accurate. It's not possible to get the data cross-origin with no-cors.

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.