-1

I can't figure out how to take a Postman GET request and use it in actual code. I get the sense that I am missing something obvious, so any direction would be appreciated.

Here is the code:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://freshdesk.freshdesk.com/support/home",
  "method": "GET",
  "headers": {
    "cache-control": "no-cache",
    "postman-token": "abfd5ad4-315f-6a16-be62-20e92ec99baf"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

In Postman if you just add the url to the GET section and hit 'Send' it will return the HTML of the page. Here is a Codepen of the same code: Codepen.

I have looked at some Postman documentation, and checked out some StackOverflow question/answers but haven't been able to find any good insight.

Thanks!

NOTE: Probably not that helpful of info, but Codepen in Chrome Canary on Mac was not giving ANY errors. When I checked in normal Chrome and Safari I got the errors one would expect.

Neal Jones
  • 450
  • 5
  • 19
  • 1
    What happens when you run the code? What problem are you seeing? – Andrew Lohr Sep 12 '17 at 20:56
  • 1
    I assume you are running into CORS issues. Try googling around using that keyword. Essentially, you cannot make client (javascript) requests to a cross domain API without it letting you. A solution can be to send this request to your server and have your server send the request from there and return the results back to your client. – Andrew Lohr Sep 12 '17 at 21:01
  • @AndrewLohr I don't recall seeing errors, but I think you're right, I'm seeing some issues in the console now. Checking those out (including the CORS)... – Neal Jones Sep 12 '17 at 21:02

1 Answers1

0

This is due to security policies (CORS) built in to the browser, which Postman doesn't have.

Your question was already asked and answered here.

Niels de Bruin
  • 705
  • 5
  • 15