0
<script>
        $(document).ready(function(){
            $.ajax({
                url:'...', 
                type: 'GET', 
                dataType: 'jsonp',
                processData: true,
                crossDomain: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader('X-SOMETHING-Key', 'lettersandnumbers')},
                success: function(data){
                    console.log(data); 
                }
            });
        });
</script>

I changed key values, because it's rather private. Also url.

And I get such errors in console:

  1. index.html:1 The SSL certificate used to load resources from ... will be distrusted in M70. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.

  2. jquery.min.js:2 GET ...callback=jQuery3310028832911017486307_1522854704209&_=1522854704210 net::ERR_ABORTED

I got order to read JSON data from url and while downloading data set header request 'X-SOMETHING-KEY' with value 'lettersandnumbers'. I didn't make any mistake in here.

  • It all seems related to the SSL issue on your cross-domain request. I'm not sure what help you're expecting with that. It's also likely you're going to encounter CORS problems too. – Rory McCrossan Apr 04 '18 at 15:23
  • @RoryMcCrossan so the problems is connected with authorization? I just don't have permission to get data from thath URL? – Wojciech Jakubek Apr 04 '18 at 15:31
  • `processData` `crossDomain` and `xhr.setRequestHeader` are all ignored for JSONP. JSONP doesn't use XHR. – Kevin B Apr 04 '18 at 15:32
  • No. From the errors you've shown it appears to be an issue with SSL security. Possibly CORS too. You may well have an authorisation problem as well, but for now that's not what these errors are saying. – Rory McCrossan Apr 04 '18 at 15:32
  • @KevinB I got: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access. After changing jsonp into json – Wojciech Jakubek Apr 04 '18 at 15:33
  • That means you aren't sending a JSONP request. though, to be fair, i don't think the server will accept a jsonp request. – Kevin B Apr 04 '18 at 15:34
  • Right, so you need to stop setting additonal headers, or make the server properly support preflights. past that, you can't make this request. – Kevin B Apr 04 '18 at 15:35
  • Given the error you posted above I'm closing this as a duplicate. It's a CORS problem. You cannot just change the expected response type on the client to JSONP. The server needs to actually return data in that format, which it's not. It's using JSON. – Rory McCrossan Apr 04 '18 at 15:36
  • @KevinB damn, I tried it on firefox (previously was trying on Chrome) and it works. I got response with data. I read sth about Chrome problems with this Acce-Control-Allow-Origin. Is there any solution? – Wojciech Jakubek Apr 04 '18 at 15:36
  • Nope. you have to follow CORS rules. Not all browsers implement them equally, so you'll have to bend to whatever browser is the most strict. – Kevin B Apr 04 '18 at 15:37
  • @KevinB could you give me some clue with these rules? Should I start with reading about CORS deeply? – Wojciech Jakubek Apr 04 '18 at 15:38
  • CORS is rather simple. You provide what it requires, or the request isn't allowed. there's no way around it other than not sending a request to that server from the browser. – Kevin B Apr 04 '18 at 15:38
  • This page is decent; https://en.wikipedia.org/wiki/Cross-origin_resource_sharing as is this one: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – Kevin B Apr 04 '18 at 15:38
  • @KevinB ok, but I still don't get what is wrong in my code. Firefox can send request and give me response with data. So what is wrong in Chrome? I got orders from IT company and i'm trying to get internship. Don't think that any clue which they gave me to get those data are wrong. – Wojciech Jakubek Apr 04 '18 at 15:47
  • Chrome requires requests with that additional header to send a preflight first. the server doesn't properly respond to the preflight, therefore the request fails. The server should be able to respond to preflights. – Kevin B Apr 04 '18 at 15:47
  • @KevinB so, who is guilty? :D me or that website from url? btw I'm trying to get those data from localhost (simply from ide/browser). Setting up server could change anything? – Wojciech Jakubek Apr 04 '18 at 15:52
  • i mean, if you're controlling both the browser and the server, there's only one who can be guilty. setting up a server doesn't change the requirements, but if it makes it easier for you to meet the requirements, then yes, that could change things. – Kevin B Apr 04 '18 at 15:53

0 Answers0