0

I am trying to connect to Sharepoint using Javascript and REST but in android, I am getting a '401 Unauthorized Error'. The app is wrapped using phonegap.

Is there anyway I can authenticate it?

$(function(){
    var myData = [];
    var requestHeaders = {
    "accept": "application/json;odata=verbose"
    }
    $.ajax({
        url: "https://sharepoint/sites/_api/Web/Lists/GetByTitle('LP')/Items",
        type: "GET",
        dataType: "json",
        asyn: false,
        headers: requestHeaders,
        success: function (data) {
            $.each(data.d.results, function (i, result) {
                $("#field1").append(result.field1);
                $("#field2").append(result.field2);
            });
        },
        error: function ajaxError(response) {
            alert(response.status + ' ' + response.statusText);
        }
    });
});
Nes
  • 581
  • 4
  • 11

1 Answers1

0

I can't tell exactly, but I used to authenticate at the Jira Rest service with the additional parameter beforeSend:

beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', make_base_auth(user, password));
            },
            error: function (errmsg) {
                alert('error ocured:' + errmsg.responseText);
            },
            success: function (text) {
                alert(text);
            },

see create Jira issue via REST api and jquery 405 method not allowed

might help.

Community
  • 1
  • 1
Simon
  • 454
  • 7
  • 18
  • Thanks for the response. I am getting this error "Uncaught ReferenceError: make_base_auth is not defined". Is there a library required for this or something? – Nes Jan 30 '15 at 07:36
  • I used this function: function make_base_auth(user, password) { var tok = user + ':' + password; var hash = btoa(tok); return "Basic " + hash; }. However, I keep on getting the authentication pop-up after typing the username and password. – Nes Jan 30 '15 at 07:40