Sorry for asking this question. I know this is a common issue but i am not able to find the solution.
I am trying to send a xmlhttprequest to a server(different domain) for invoking rest service,
What I tried is:
ad1,city,sp,pc,cn will taken by getElementbyID.
var url='http://*******:***/rest/code/results.json'+'?AddressLine1='+ad1+'&City='+city+'&StateProvince='+sp+'&PostalCode='+pc+'&Country='+cn;
var req;
if (typeof XMLHttpRequest != "undefined")
{
req = new XMLHttpRequest();
}
else
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
req = new ActiveXObject("Microsoft.XHTTP");
}
}
// populate the request, username and password
var userName ='admin';
var password = 'admin';
//Execute the REST request against a server secured with Basic Authentication
req.open("GET",url,true,userName,password);
req.send();
//Display the response
var resp = req.response;
alert(resp);}
output what I am getting is an alert with no data.
In web browser console , it is showing as
Error 1: "url(Server rest service url with input parameters) 401 (Unauthorized) " and
Error 2: XMLHttpRequest cannot load url(Server rest service url) Origin http://**:8081(My machine IP) is not allowed by Access-Control-Allow-Origin.
If i opened the url(Server rest service url with input parameters) in new tab, i am getting the output.
Any help is greatly appreciated ..
Thank you.