0

I am trying to query the Reed jobs site to return Construction based jobs in Sheffield.

I have tried literally everything I can think of and posted numerous posts on here to try and get the code to work but to no avail.

Can someone please try the code themselves and see if they can work it out?

Any help is greatly appreciated.

<script>
$(function (){

  var $jobs = $('#jobs');

  $.ajax({
    type: 'GET',
    dataType: 'jsonp',
    username: '5afe0f90-3480-4d47-8206-3529815a610a',
    password: '',
    crossDomain: true,
    url: 'http://www.reed.co.uk/api/1.0/search?keywords=construction&location=sheffield',
    success: function(jobs) {
      $.each(jobs, function(i, job){
        $jobs.append('<li>my job</li>')
      });
    },
    error: (err)=> {alert(err)}
  });

});
</script>

<ul id="jobs"></ul>```
Alex Posterns
  • 23
  • 1
  • 8
  • Assuming this isn't a CORS problem, then you most likely need to encrypt the username/password and include it in the request as a basic authentication header. Check the documentation. – Rory McCrossan Oct 04 '19 at 20:21
  • use https instead of http. and check your network tab to see the status. – Ahmed Sunny Oct 04 '19 at 20:46
  • you can try remove username and password, and add the following instead: beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic " + btoa('5afe0f90-3480-4d47-8206-3529815a610a:' )); }, – SuleymanSah Oct 04 '19 at 22:01
  • @SuleymanSah I have implemented your solution but still no luck. I have created a CodePen example. https://codepen.io/FluxedDigital/pen/oNNNBbx – Alex Posterns Oct 05 '19 at 12:05
  • This api really seems to very difficult to call :( – SuleymanSah Oct 05 '19 at 12:07
  • @SuleymanSah I know :( I don't know if its any help but here is the documentation! https://www.reed.co.uk/developers/Jobseeker – Alex Posterns Oct 05 '19 at 12:09
  • @SuleymanSah the request works in post man which is strange – Alex Posterns Oct 05 '19 at 12:23
  • @SuleymanSah I just get this error alert now `[object Object]` – Alex Posterns Oct 05 '19 at 12:27
  • @RoryMcCrossan I have, but can can't see anything. The request works fine in PostMan https://www.reed.co.uk/developers/Jobseeker – Alex Posterns Oct 05 '19 at 12:32
  • The important part is right at the bottom: `Important: You will need to include your api key for all requests in a basic authentication http header as the username, leaving the password empty.` – Rory McCrossan Oct 05 '19 at 13:50
  • @RoryMcCrossan I have included the username in the script – Alex Posterns Oct 05 '19 at 14:15
  • I don't believe that's quite the same as a basic authentication header. See this answer: https://stackoverflow.com/a/10226395/519413 – Rory McCrossan Oct 05 '19 at 14:28
  • I could called the api within nodejs, but no luck within vanilla javascript. – SuleymanSah Oct 05 '19 at 18:11