# Ajax Request to an outer origin/host

**URL:** <https://community.hubspot.com/t/ajax-request-to-an-outer-origin-host/19373>\
**Category:** CMS Development\
**Tags:** content\
**Created:** [March 11, 2020, 3:23pm UTC](https://community.hubspot.com/t/ajax-request-to-an-outer-origin-host/19373 "2020-03-11T15:23:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikotech](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rikotech/32/26012_2.png) [@rikotech](https://community.hubspot.com/u/rikotech)\
**Post date:** [March 11, 2020, 3:23pm UTC](https://community.hubspot.com/t/ajax-request-to-an-outer-origin-host/19373/1 "2020-03-11T15:23:17Z")

</div>

Hello,

1. Iam trying to fetch some data from external website/source via JQuery Ajax request.

Here is an example:

`$(document).ready(function() {$.ajax({type: "GET",url: "https://stage.csrhub.com/number",headers: {'Authorization': "Basic " + btoa("myusername" + ":" + "mypassword")},success: function (data, status){console.log(data);alert('Thanks!'); },error: function(jqXhr, textStatus, errorMessage){console.log(textStatus);console.log(errorMessage);}});});`

I am getting the following log in the console:

 ![Ajax.PNG](https://d2qpr2jzcazej7.cloudfront.net/original/2X/7/710e13e069d2b484fd957849850899ce7efbc352.png)

Is it possible at all to request outer domains from HS CMS?

2. In case it is posible, how can I assign HubL-variable with the response of the request?

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [March 12, 2020, 3:54pm UTC](https://community.hubspot.com/t/ajax-request-to-an-outer-origin-host/19373/2 "2020-03-12T15:54:20Z")

</div>

Hey @rikotech,  
If you have access to the server of the external site the best option here would be to setup CORS to allow the access. [Cross-Origin Resource Sharing (CORS) - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)  
If you don’t have access then you can kind of ‘hack’ it by adding a datatype of JSONP to your ajax request like so:

```auto
<script>
$(document).ready(function() {
 $.ajax ({
 type: "GET",
 url: "https://stage.csrhub.com/number",
 dataType: 'jsonp', <!----- JSONP ADDITION ----->
 headers: {
 'Authorization': "Basic " + btoa("myusername" + ":" + "mypassword")
 },
 success: function (data, status){
 console.log(data);
 alert('Thanks!'); 
 },
 error: function(jqXhr, textStatus, errorMessage){
 console.log(textStatus);
 console.log(errorMessage);
 }
 });
});
</script>

```

For adding HubL, as long as you are adding the code somewhere that allows HubL (an HTML/HubL file or the HTML/HubL section of a custom module) you can use the variables like you would in HTML.

```auto
<script>
$(document).ready(function() {
 $.ajax ({
 type: "GET",
 url: "https://stage.csrhub.com/number",
 dataType: 'jsonp', <!----- JSONP ADDITION ----->
 headers: {
 'Authorization': "Basic " + btoa("myusername" + ":" + "mypassword")
 },
 success: function (data, status){
 console.log(data);
 alert('Thanks!'); 
 },
 error: function(jqXhr, textStatus, errorMessage){
 console.log(textStatus);
 console.log({{ module.error_message }}); <!---- EXAMPLE HUBL --->
 }
 });
});
</script>

```
