[英]why this javascript code doesn't work
There are two codes. 有两个代码。 one works the other doesn't work.
一个有效,另一个无效。
I debugged it and I found that 我调试了它,发现
"var eb = new EventBus(" http://192.168.0.27:8081/bridge ");" “” var eb = new EventBus(“ http://192.168.0.27:8081/bridge ”);“
this line in login.js doesn't work well. login.js中的这一行无法正常运行。
Thank you so much everytime. 每次都非常感谢。
working 工作中
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script src="vertx-eventbus.js"></script>
</head>
<style>
.news {
font-size: 20pt;
}
</style>
<body>
<div class="news">Latest news:</div>
<br>
<div id="status" class="news"></div>
<script>
var eb = new EventBus("http://192.168.0.27:8081/bridge");
eb.onopen = function() {
// set a handler to receive a message
eb.registerHandler('call', function(error, message) {
console.log('received a message: ' + JSON.stringify(message));
});
// send a message
eb.send('call', {name : 'tim', age : 587});
}
</script>
</body>
</html>
no working - login.html 无法正常工作 -login.html
<!DOCTYPE html>
<!--
login.html
-->
<html>
<head>
<meta charset="UTF-8">
<title>Flat HTML5/CSS3 Login Form</title>
</head>
<body>
<div class="login-page">
<div class="form">
<form class="login-form" id="loginForm">
<input type="text" id="username" placeholder="username" />
<input type="password" id="password" placeholder="password" />
<input class="submit" type="submit" title="Login" value="Login" onclick="check(this.form)" />
<p class="message">
Not registered? <a href="#">Create an account</a>
</p>
</form>
</div>
</div>
<script src="js/login.js"></script>
</body>
</html>
login.js login.js
document.write("<script src='https://code.jquery.com/jquery-1.11.2.min.js'></script>");
document.write("<script src='//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js'></script>");
document.write("<script src='/vertx-eventbus.js'></script>");
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.username.value != "" && form.password.value != "") {
var eb = new EventBus("http://192.168.0.27:8081/bridge");
eb.onopen = function() {
// set a handler to receive a message
eb.registerHandler('call', function(error, message) {
console.log('received a message: ' + JSON.stringify(message));
});
// send a message
eb.send('call', {name : 'tim', age : 587});
}
} else {
alert("Input Password or Username")/*displays error message*/
}
}
You have written 你写
document.write("<script src='/vertx-eventbus.js'></script>");
differently than in the working code. 与工作代码不同。 There is an extra "/" before "vertx..".
在“ vertx ..”之前有一个额外的“ /”。 Could that be the problem?
这可能是问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.