ajax - Having trouble making an HTTP request to an API using Bigcommerce -


so i'm working on bigcommerce build website client. since bigcommerce not allow upload of php files on system i'm using ajax in script tag in html file. documentation api i'm using says use api key in username field http basic authentication, , requests must transmitted on https.

so firstly, here's code

$.ajax({         type: 'post',         url : "https://www.freightview.com/api/v1.0/rates",         data : ({ myrequest }),         datatype : "jsonp",         accept: 'application/json',         beforesend : function(xhr) {         xhr.setrequestheader("authorization", "basic " +           "mykey:");         } }) 

i've tried doing username : 'mykey' , other various ways put key in there keep getting 401 unauthroized

i've searched around ways , noted few possible issues:

  • ajax request on https it's mentioned on page ajax cannot make cross-domain https requests. mean have find way make request? if so, how can make such request limitations have?
  • is i'm not defining username authentication? i'm hoping problem, i've looked @ lot of questions on site basic auth in ajax.
  • jquery ajax calls http basic authentication user asks question seems have similar problem mine, answers quite varied, , i'm not sure if they'll work in situation or how begin implementing them. need cors? can cors work on bigcommerce?

so can see thought relatively simple snippet of code turned out lot more complex thought, , use of stackoverflow magic!

edit: grammar , spelling

in bigcommerce have encode credentials base64.

example:

// define string var string = 'hello world!';  // encode string var encodedstring = btoa(string); console.log(encodedstring); // outputs: "sgvsbg8gv29ybgqh"  // decode string var decodedstring = atob(encodedstring); console.log(decodedstring); // outputs: "hello world!" 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -