title: Calling External API with Javascript
body: <p>I need to make a POST request to an external server from my webpage using Javascript. The body and response are both json. I can't figure out how to make this call or what tools to use. How do I make this call?</p>
  
  <p>This is what I have so far using jQuery and ajax:</p>
  
  <pre><code>var body = '{"method":"getViews","params":{"filter":{"operator":"and","clauses":[{"operator‌​":"matches","value":"'+ inputValue +'"}]},"order":[{"field":"name","ascending":true}],"page":{"startIndex":0,"maxIt‌​ems":5}}}';
  var response = $.ajax({
             url: "http://" + environment + "/vizportal/api/web/v1/getViews",
             method: "post",
             dataType:'json',
             data: JSON.stringify(body),
             headers: {
              'Content-Type': 'text/plain',
              'X-XSRF-TOKEN' : XSRFToken,
              'Cookie': 'workgroup_session_id='+workgroupSessionId+';XSRF-TOKEN='+XSRFToken
             },
             success:function(response){
                  alert("success");
              },
              error: function(XMLHttpRequest, textStatus, errorThrown) { 
                  alert("Status: " + textStatus); alert("Error: " + errorThrown); 
              } 
          });
  </code></pre>
  
  <p>It is throwing a alerts that just says "Status:" and "Error:"</p>
  
  <p>The console says this "XMLHttpRequest cannot load <a href="http://[domain]/vizportal/api/web/v1/getViews" rel="noreferrer">http://[domain]/vizportal/api/web/v1/getViews</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://[domain]" rel="noreferrer">http://[domain]</a>' is therefore not allowed access. The response had HTTP status code 405."</p>