REST API with Javascript


#1

Hi All,

I am a noob to javascript so sorry about my dumb questions. I have a cloud product which supports REST api, i am trying to build a webpage to show some content from my cloud. this is what i am doing now.

wrote a simple index.html and calling javascript, and below is my javascript, but not sure how to pass authentication and also trust the self signed certificate. Finally send the output onto webpage.

//Javascript
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://192.168.110.106/api/2.0/vdn/scopes/", false);
xhr.setRequestHeader('Content-Type', 'application-xml');
xhr.setRequestHeader("Authorization", "Basic " "YWRtaW46Vk13YXJlMSE=");
// Add your code below!
xhr.send()
var status = console.log(xhr.status);
var statustext = console.log(xhr.statusText);
alert(status text);

//index.html





Welcome to NSX Automation




--Shankar


#2

index.html is like below:





Welcome to NSX Automation




.

#3

the same error hereā€¦

It seems that console.log(xhr.statusText); is not running correctly.

The same error in exercise 5. Making Requests.


#4

Please see existing topics, for example this one:

Requests

it covers why its not working (course is no longer maintained), and how to pass the exercise (even though i would recommend updating to a supported course)