我正在使用带有express的socketIO.
在我的项目中,我有一个登录页面和一个主页.当我成功登录时,我导航到localhost:3000/home,我收到此错误:
GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1418187395022-0 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
我没有在app.js(由express创建的项目)中进行任何修改.
Index.js:
var express = require('express');
var router = express.Router();
var http = require('http');
var fs = require('fs');
var io = require('socket.io')(http);
/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});
router.get('/home', function(req, res) {
res.render('home', { title: 'Express' });
});
io.on('connection', function(socket){
console.log("User Connected");
socket.on('chat message', function(msg){
io.emit('chat message', msg);
console.log("Message");
});
socket.on('disconnect', function(msg){
console.log("User DisConnected");
});
});
router.post('/authenticate', function(req, res) {
fs.readFile("./public/Verification/Users.json", "utf8", function (err, …
Run Code Online (Sandbox Code Playgroud) 我想这个标题非常清楚我要问的是什么.我创造了这个小提琴:http://jsfiddle.net/Sourabh_/HB7LU/13142/
在小提琴中,我试图复制一个async
场景.这只是一个例子,但在AJAX调用中如果我不使用$scope.$apply()
该列表则不会更新.我想知道$scope.$apply()
每次进行AJAX调用更新列表时是否安全使用,还是有其他一些我可以使用的机制?
我编写的代码用于复制场景(与小提琴相同):
HTML
<div ng-controller="MyCtrl">
<li ng-repeat="item in items">
{{item.name}}
</li>
<button ng-click="change()">Change</button>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.items = [{name : "abc"},{name : "xyz"},{name : "cde"}];
$scope.change = function(){
test(function(testItem){
$scope.items = testItem;
//$scope.$apply();
})
}
function test(callback){
var testItem = [
{name : "mno"},
{name : "pqr"},
{name : "ste"}
];
setTimeout(function(){callback(testItem)},2000);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在加载视图时显示模态.
代码:
//View
<div id="showCom" ng-controller="showmodalCtrl" ng-init="init()">
<div class="modal fade" id="companyModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Please Select Company</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label class="control-label">Recipient:</label>
<input type="text" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
//Controller
.controller('showmodalCtrl', ['$scope', function($scope){
$scope.init = function(){
$('#companyModal').modal("show");
}
}])
Run Code Online (Sandbox Code Playgroud)
一切正常,显示模式,但我在控制台上收到此错误:
Type error : Cannot read property 'childNodes' of undefined
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.此外,如果我从模态中删除"表单",我不会收到任何错误.所以我猜问题是表单,但我无法解决它.
提前致谢.
我对JS和Web开发世界都很陌生,所以如果我的问题有点乏味,请提前道歉.
我写了这段代码:
var breakfast = new Object();
breakfast.food = "croissant";
breakfast.extra = ["mushroom", "cheese"];
breakfast.eat = function(){return this.food + " with " + this.extra[0];}
var elBreakfast = document.getElementById("breakf");
elBreakfast.textContent = breakfast.eat();
Run Code Online (Sandbox Code Playgroud)
我从浏览器收到错误消息:
"Uncaught TypeError: Cannot set property 'textContent' of null"...
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
谢谢!
HTML:
<img src="img/image1.jpg" id = "image1" style="width: 100%;" allign = "center">
Run Code Online (Sandbox Code Playgroud)
JavaScript:
var image1 = document.getElementById("image1");
Run Code Online (Sandbox Code Playgroud)
我如何获得该给定图像的中心,然后将另一个具有绝对位置的图像放置在其死点之上?
我想将一个JSON对象从一个控制器传递给另一个控制器.我怎么做?
或者我可以将oModel传递给另一个视图吗?如果是这样,我该怎么做?
谢谢
我正在制作一个简单的插件函数,在单击时将元素的背景颜色变为红色.我添加了如下所示的代码,但无法在点击时获得按钮的背景颜色.有人可以更正代码吗?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$.fn.red({
red:function(){return this.each(function(){this.style.background=red;})}
});
</script>
</head>
<body>
<button onclick="red()">Red</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 在我正在构建的网页中,我使用AngularJS ng-hide
来显示隐藏元素(基本上是一个按钮).但实际上它只是ng-hide
为该元素添加一个类.
所以任何人都可以访问开发人员工具并删除该类ng-hide
,该按钮将可见.我知道使用jQuery我可以完全remove
从HTML中的元素,但有没有办法在角度?
在它看起来像这样之前:
<button ng-hide="hide">Button</button>
Run Code Online (Sandbox Code Playgroud)
隐藏后它看起来像:
<button class="ng-hide">Button</Button>
Run Code Online (Sandbox Code Playgroud) 我想在单击按钮时隐藏按钮/区域/区域(页眉,页脚等).我怎样才能做到这一点?例如,如果我有以下页面:
<mvc:View
height="100%"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Page
title="Hide Area On Button Click" >
<content>
<Button id="btn1" text="Accept" type="Accept" press="onPress" />
<Button id="btn2" text="Reject" type="Reject" />
</content>
<footer>
</footer>
</Page>
</mvc:View>
Run Code Online (Sandbox Code Playgroud)
现在应该是什么
onPress : function {//code}
Run Code Online (Sandbox Code Playgroud)
隐藏拒绝按钮?
我试图使用setInterval来调用将使用ajax加载订单的函数.但是,当我将一个参数传递给回调时,setInterval函数停止工作.w ^
母鸡我没有传递它开始工作的任何论据.
关于如何让它与参数一起工作的任何想法?以下是我的代码
先感谢您!
function httpGetRequest(page){
$.get(page)
.done(function(data){
$(".display_orders").html(data);
});
}
setInterval(httpGetRequest('load_orders.php'), 30000);
Run Code Online (Sandbox Code Playgroud) 我试图将一个变量从javascript发布到同一个php页面.这是代码:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
</head>
<body>
<?php echo 'Result is '; if (isset($_GET['testing'])) { echo $_GET['testing']; } ?>
<?php $thisPage = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>
<script>
$(document).ready(function() {
$('#testing123').on('change',function () {
var testing = "confirmed";
$.ajax({
type: "GET",
url: "<?php echo $thisPage; ?>",
data: testing,
success: function() { $('#showresult').html("success"); }
})
});
});
</script>
<form>
<select id="testing123">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<div id="showresult"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用POST,但不会在php中使用.还尝试使用单独的php文件并使用include_once()仍然无法正常工作.
我错过了要加载的文件吗?
希望是一个简单的,但我无法从for循环打印出一个数字系列,回到HTML.看下面我的代码,当我点击按钮时,它只返回10,但不是其他数字 - 我哪里错了?
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try It</button>
<p id="number"></p>
<script>
function myFunction() {
for (i=0; i<11; i++) {
document.getElementById("number").innerHTML=i+"</br>";
}
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)