How to add authentication to jquery

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() {





return false;




Kindly advice

1 answer

This widget could not be displayed.

you have to pass username and password as follows

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

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!!!

I already saw this.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

569 views 7 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you