Hello developers,
My new homework is:
-to doing crypto chat between two people
There are should have new reg,login,logout & chat
The server is programmed by another company and I should do only Javascript coding.
But when I try to create new reg and server returns me bad request?

This is JS code:
//server url --> cryptoChat
var serviceUrl = "http://cryptochat.apphb.com/CryptoChatService.svc/";
var m = new Array();

var hash = function (a, b) { CryptoJS.SHA1(a + b) };
//handler --> when page loaded
$(document).ready(function () {
$("#sumbit-btn").on("click", onRegButtonClick);
$("#login").on("click", onLogInBtnClick);
$("#logOut_").on("click", onLogOutBtnClick);
});

//When user click on the reg button
function onRegButtonClick(ev) {
var userData = formRegData();
function validatePass(ev) {
if (userData.password != userData.repPassword) {
alert("Passwords do not match!");
ev.preventDefault();
return;
}
else if (userData.password == "") {
alert("Password is empty!");
ev.preventDefault();
return;
}
else if (userData.password < 4) {
alert("Password should be more than 4 characters");
ev.preventDefault();
return;
}
else {
return true;
}
return userData.password;
}
function validateUsename(ev) {
if (userData.username >= 30) {
alert("Username is too long!");
ev.preventDefault();
return;
}
else if (userData.username == "") {
alert("Username is empty!");
ev.preventDefault();
return;
}
else if (userData.username <= 4) {
alert("Usename is less than 4 characters!");
ev.preventDefault();
return;
}
else {
return true;
}
return userData.username;
}

var user = {
username: userData.username,
authCode: userData.authCode
};
postRequest(serviceUrl + "register", user , onRegSuccess, onRegWrong);
ev.preventDefault();
};
function formRegData() {
var user = {
username: $("#user-tb").val(),
password: $("#pass-tb").val(),
repPassword: $("#repPass-tb").val(),
authCode: function() {
return hash(this.username ,this.password);
}
};
return user;
};
function onRegWrong(err) {
alert(JSON.stringify(err));
}
function onRegSuccess(data) {
alert(JSON.stringify(data));
var result = m.push(data);
//$("#logInform").hide();
//$("#logOut").show();
//$("#logOut").append("<span>Hello"+ data.username + "</span>");
}

//When user click on the login button
function onLogInBtnClick(ev) {
var onLogIn = formRegData();
function checkUsername() {
for (var i = 0; i < m.length; i++) {
var res = m[i].username;
if(res == onLogIn.username ) {
return true;
}
else {
return false;
}
return res;
}
}
function checkAuthCode() {
for (var j = 0; j < m.length; j++) {
var authCode = m[j].user.authCode;
if(authCode == onLogIn.authCode){
return true;
}
else {

}
return authCode;
}
}
var logIn = {
checkUser: checkUsername,
authCode: checkAuthCode
};

postRequest(serviceUrl + "login",logIn,onSuccessLogIn,onErrorLogIn);
ev.preventDefault();
}

function onSuccessLogIn(data) {
alert("You have entered in the system!");
$("#logInform").hide();
$("#logOut").show();
$("#logOut").append("<span>Hello" + data.username + "</span>");
}
function onErrorLogIn() {
alert("");
}


//When user click logout button
function onLogOutBtnClick(ev) {
var logOut = formRegData();
for (var i = 0; i < m.length; i++) {
var users = logOut.username;
var authCode = logOut.authCode;
if (users == logOut.username[i]) {
return true;
}
else {
return false;
}
if (authCode == logOut.authCode[i]) {
return true;
}
else {
return false;
}

}

getRequest(serviceUrl + "logout/" + "sessionID", onLogOutSuccess, onLogOutError);
ev.preventDefault();
}
function onLogOutSuccess(data) {
alert("LogOut Success!")
$("#logInform").show();
$("#logOut").hide();
}
function onLogOutError(err) {
alert("Logout Error!");
}
//GET & POST requests
function getRequest(serviceUrl, onSuccess, onError) {
$.ajax({
url: serviceUrl,
type: "GET",
timeout: 4500,
dataType: "json",
success: onSuccess,
error: onError
});
}
function postRequest(serviceUrl, data, onSuccess, onError) {
var data_ = JSON.stringify(data);

$.ajax({
url: serviceUrl,
type: "POST",
timeout: 4500,
dataType: "json",
contentType: "aplication/json",
data: data_,
success: onSuccess,
error: onError

});
}



This is HTML code:
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Crypto_chat</title>
<link href="css/crypto.css" rel="stylesheet" />
<script src="js/jquery-1.9.1.js"></script>
<script src="js/cryptoChat.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<ul id="top_menu">
<li><a href="#">Online users</a></li>
<li><a href="new_reg.html">New registration</a></li>
</ul>
<div class="reg_form">
<form action="" name="login" id="logInform">
<span><input type="text" value="username" onfocus="if (this.value == 'username') { this.value = '' };" onblur="if(this.value == ''){this.value='username'}" /></span>

<span><input type="text" value="authCode" onfocus="if (this.value == 'authCode') { this.value = '' };" onblur="if(this.value == ''){this.value='authCode'}" /></span>
<button id="login">Login</button>
<a href="#">Forgot your password?</a>

</form>
</div>
</div>
<div id="content_part">
<div class="users">
<div class="view_users">
<p>All users</p>
<ul>
<li><a href="#">Ivan Ivanov Ivanov</a></li>
<li class="special"><a href="">Geoirgi Ivanov Georgiev</a></li>
<li><a href="">Bojidar Jelev Kirilov</a></li>
<li><a href="">Blagoj Ivanov Stoichev</a></li>
<li><a href="">Pesho Peshev Peshev</a></li>
<li><a href="">Dimitur V3n3v </a></li>
<li class="special"><a href="">Dalin Ivanov</a></li>
<li><a href="">Osmi Osmichev</a></li>
<li class="special"><a href="">Hristofor Krustev Krustev</a></li>
<li><a href="">Elena Ivanova Ivanova</a></li>
</ul>
<input type="search" value="search your friend" onfocus="if(this.value == 'search your friend'){this.value=''}" onblur="if(this.value==''){this.value='search your friend'}" />
<button>Go to chat</button>
</div>
</div>
<div class="chat">
<form action="" name="">
<textarea cols="90" rows="20" name="chat" scrolling="scrolling" disabled="disabled"></textarea>
<textarea cols="90" name="chat" scrolling="scrolling" ></textarea>
<button>Send a message</button>
</form>

</div>
</div>
</div>
</body>
</html>


Thanks so much: