0

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.

Phalanx
  • 1,217
  • 6
  • 25
  • 36
  • Did you check this link? [http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax][1] [1]: http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax – nab_kc May 05 '14 at 10:05
  • Thanks for your reply. Yeah, I saw this post already, I tried to use some code but it didn't help me to solve my problem. There are usually too many prerequisite to understand the solution, and I am still trying to find a clear, simple example that shows how to simply create an HTML file and use jQuery to get JSON data from a webservice. Nothing more, nothing less. Instead I just keep finding a few lines of code that seem useful but that I can't assemble properly. – Phalanx May 05 '14 at 11:06

0 Answers0