I am talking about something I really do not master at all so please excuse me if some things are not properly expressed.
I have to write an HTML page that will serve as an interface to connect to a webservice, and that I will use to retrieve JSON data using jQuery.
So I have all the information I need (the URL to my webservice, the password and the user name) and the data are ready in JSON on the WS. I have tried some things using code I have found here but nothing helped me to access the data on the WS so far...
Here is a code I tried:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$.ajaxSetup({
beforeSend: function (xhr, settings) {
var creds = {
username: "user",
password: "pass"
};
xhr.setRequestHeader("Authorization", "Basic " + btoa(creds.username + ":" + creds.password));
return true;
}
});
$.ajax({
type: "GET",
data: "{'prefix':''}",
url: "http://aaaaa.com/aaaaa/ws/getListSortir.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: functionToCallWhenSucceed,
failure: functionToCallWhenFailed
});
</script>
</head>
<body>
<br />
<input type="button" id="jsonButton" onclick="GetJson()" value="Envoyer requete" />
<br />
<br />
<div id="jsonData">
</div>
</body>
</html>
Nothing happens when I load the page or click the button (I don't even really now if the button is actually assigned to anything).
I would really appreciate some guidance to understand how to solve this,
Thanks in advance.