Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add authentication to jquery

Mustafa Abusalah October 8, 2013

I have the below script and I want to add username and password to be able to query confluence:

<script type="text/javascript">

$.ajaxSetup ({

cache: false

});

$(function() {

$("#submit").click(function() {

var request = $.ajax({

type: "POST",

data: JSON.stringify(

{"jsonrpc" : "2.0", "method" : "getSpaces", "params" : [], "id": 12345 }

),

//Please change <confluence-url> to the relevant url

url: "rpc/json-rpc/confluenceservice-v2",

async: false,

cache: false,

contentType: "application/json",

success: function() {

//alert("success");

}

});

$("#output").html(JSON.stringify(request));

return false;

});

});

</script>

Kindly advice

1 answer

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013

you have to pass username and password as follows

$.ajax
({
  type: "GET",
  url: "URL",
  dataType: 'json',
  async: false,
  username: username,
  password: password,
  data: '{ "comment" }',
  success: function (){
    alert('Thanks for your comment!'); 
  }
});

Mustafa Abusalah October 8, 2013

I tried this it did not work, I'm trying to use basic http authorization as the below:

beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Basic " + encodeBase64("username" + ":" + "password")); },

it is not returning error, but also not returning results!!!

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013
Mustafa Abusalah October 9, 2013

I already saw this.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence, marketing templates, confluence templates, marketing project management, content strategy, campaign planning, marketing collaboration, confluence for marketers, atlassian learning, marketing workflows, confluence best practices

5 must-use templates for Marketing teams (from a Confluence Marketer!) 👩🏻‍🎨

Who doesn’t love a good template? We sure do! Check out our top template picks for Marketing teams who want to streamline their processes, enhance collaboration, and take their marketing to new heights.

Read more 📚
AUG Leaders

Atlassian Community Events