Here a small portion of the apache log, i'm guessing that although for queue the session username and password are used, for background actions they are not. thus no username / password is passed along and it returns a 401.
You stated that moving it in background.html would improve things maybe.
As i said i also included a username: 'user', password: 'password', in the $.ajax but that didn't help at all.
192.168.0.6 - - [12/Mar/2010:17:17:04 +0100] "GET /nzb/api?apikey=3d2da55e891326b1e7a6bd8d746949e1&mode=queue&output=json&limit=5 HTTP/1.1" 401 406 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - - [12/Mar/2010:17:17:05 +0100] "GET /nzb/ HTTP/1.1" 401 408 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:06 +0100] "GET /nzb/ HTTP/1.1" 200 3236 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:06 +0100] "POST /nzb/queue/ HTTP/1.1" 200 593 "
http://www.domain.nl/nzb/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:06 +0100] "POST /nzb/history/ HTTP/1.1" 200 2231 "
http://www.domain.nl/nzb/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:08 +0100] "GET /nzb/ HTTP/1.1" 200 3236 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:08 +0100] "POST /nzb/queue/ HTTP/1.1" 200 593 "
http://www.domain.nl/nzb/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - username [12/Mar/2010:17:17:08 +0100] "POST /nzb/history/ HTTP/1.1" 200 2231 "
http://www.domain.nl/nzb/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"
192.168.0.6 - - [12/Mar/2010:17:17:14 +0100] "OPTIONS /nzb/api?apikey=3d2da55e891326b1e7a6bd8d746949e1&mode=addurl&name=http%3A%2F%2Fwww.tvnzb.com%2Fnzb%2F37990 HTTP/1.1" 401 406 "
http://www.tvnzb.com/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, lik$
192.168.0.6 - - [12/Mar/2010:17:17:15 +0100] "OPTIONS /nzb/api?apikey=3d2da55e891326b1e7a6bd8d746949e1&mode=addurl&name=http%3A%2F%2Fwww.tvnzb.com%2Fnzb%2F37991 HTTP/1.1" 401 406 "
http://www.tvnzb.com/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, lik$
192.168.0.6 - - [12/Mar/2010:17:17:15 +0100] "OPTIONS /nzb/api?apikey=3d2da55e891326b1e7a6bd8d746949e1&mode=addurl&name=http%3A%2F%2Fwww.tvnzb.com%2Fnzb%2F37934 HTTP/1.1" 401 406 "
http://www.tvnzb.com/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, lik$
1
I think this holds the answer:
http://coderseye.com/2007/how-to-do-htt ... -ajax.html