Uncaught ReferenceError: SinchClient is not defined(anonymous function) @ backend.js:17
我有一个假设的脚本,用于提供注册和登录。好吧,显然使客户本身不成功。下面是代码。
P.S。如果我忽略了一个非常简单的错误,我完全道歉
P.S.S一个美学上令人愉悦的网站不是我的目标,只是代码
编辑:我在错误的订单中加载了我的脚本,感谢HAMMS
"use strict";
//Pre-Setup
var globalUsername = "";
var session_key = Math.round(Math.random() * 100000) + 1;
session_key = session_key.toString();
var session_id = "pstn-session-" + session_key;
//Configuration
var application_key = "a5d826f0-4a0a-48a1-8f82-6e7b5c641d5a";
var session_object = JSON.parse(localStorage[session_id] || "{}");
/*
Declare functions here
Normally I would have I/O code here
Make the client
*/
var callingclient = new SinchClient({
applicationkey: application_key,
capabilities: {
calling: true
},
startActiveConnection: true
});
//Check if user has previously signed up
if (session_object.userId) {
callingclient.start(session_object);
globalUsername = session_object.userId;
localStorage[session_id] = {
ID: session_id,
Key: session_key,
Host: function () {
if (globalUsername === "") {
return "#undefined#";
} else {
return globalUsername;
document.getElementById("h3#state-username")
.text = globalUsername;
}
}
}
} else {
document.getElementById("systemMessages")
.text = "Looks like you have an account,log in!";
}
//Assess buttons to their functions
document.getElementById("button#submit")
.on('click', function (event) {
event.preventDefault();
var sign_up_object = {}
sign_up_object.username = document.getElementById("input#usernames").val();
sign_up_object.password = document.getElementById("input#passwords").val();
//Add-Ons
sign_up_object.firstname = document.getElementById("input#first-name").val();
sign_up_object.lastname = document.getElementById("input#last-name").val();
callingclient.newUser(sign_up_object, function(ticket) {
callingclient.start(ticket, function() {
globalUsername = sign_up_object.username;
})
})
})
<!DOCTYPE html>
<html>
<head>
<title>EAD</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="backend.js"></script>
<script type="text/javascript" src="sinch.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>
<body>
<div id="header" style="text-align: center;">
<h1>Stripped-Down PSTN</h1>
</div>
<form id="accountControl" style="background-color: green; padding: 10px;">
<h2 id="state-username">Account Of: #undefined#</h2>
<button id="logOut">Log Out</button>
</form>
<form id="signup" style="background-color: #FAFAFA; padding: 10px;">
<h2>Sign Up</h2>
<input id="usernames" placeholder="Username" value="" type="text">
<input id="passwords" placeholder="Password" value="" type="text">
<p>Name</p>
<input id="first-name" placeholder="First" value="" type="text">
<input id="last-name" placeholder="Last" value="" type="text">
<button id="submit">Sign Up</button>
</form>
<br>
<br>
<br>
<form id="login" style="background-color: #CCC; padding: 10px;">
<h2>Login</h2>
<input id="usernamel" placeholder="Username" value="" type="text">
<input id="passwordl" placeholder="Password" value="" type="text">
<button id="Login">Login</button>
</form>
<br>
<br>
<br>
<br>
<br>
<br>
<div id="callpad" style="padding: 10px; background: #2196F3;">
<form id="callingo">
<h2>Call Someone!</h2>
<input id="phone-num" placeholder="Phone Number" value="" type="text">
</form>
</div>
<h3 id="systemMessages">No messages from system</h3>
</body>
</html>
-Farouk Charkas