javascriptjqueryajaxpostman

Using jQuery AJAX Postman Code Outside Postman is Failing


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 Stack Overflow question/answers but haven't been able to find any good insight.

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.


Solution

  • 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.