如果我在 Node.JS 中创建一个简单的服务器
var httpServer = http.createServer(callback);
httpServer.on('connect', function(req, socket, head){
console.log('connect');
});
httpServer.listen(3128, '192.168.0.2');
Run Code Online (Sandbox Code Playgroud)
收到connect活动后应该怎么做?
背景
connect将触发该事件理想情况下,我想做的是将请求代理到终端服务器,然后给客户端响应。
但我在这里看不到任何 API。该connect回调不具备的普遍观点(request, response),而是接受(request, socket, head)。
我如何满足请求并发出响应?
嘿我有选择框用长方法绑定到它的html中的选择框看起来像这样:
HTML:
<select id="select1">
<option>First select Advertiser</option>
<?php
buildSelectOptionsFromPagination(); // Dynamically build the options list
?>
</select>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
$('#select1').change(function(){
alert('#select1');
$('#innerP').remove();
$('#innerH').remove();
$('#waitmsg').append(' ...</h2></p>');
$("#show_c ").attr("disabled", true);
$.ajax({
url: 'observer.php',
data: "ctrl=in&v_id="+v_id,
success: function(data) {
var newData = "<option id=\"firstopt_insert\"> blah blah <\/option>" + data;
$('#in111').html(data);
$('#in222').trigger('change');
},
error: function (request, status, error) {
alert(request.responseText+"\nThere was an server error please refresh the page 1 ");
}
});
});
Run Code Online (Sandbox Code Playgroud)
现在我尝试触发这个选择框更改方法,但没有成功,从外面我触发2方法,1.通过索引选择选项,这很好用:
$('#select1 option')[5].selected = true;
Run Code Online (Sandbox Code Playgroud)
2现在我想触发更改方法方法,但没有成功,如下所示:
$('#select1').trigger('change');
or
$('#select1').bind('change', function(){ ; }); …Run Code Online (Sandbox Code Playgroud) 我正在使用 sails.js 开发一个简单的 Web 应用程序。
在我的前端代码中,我循环遍历控制器发送的对象数组,并且正在搜索特定对象。我想在找到对象后打破循环。有没有一种干净的方法可以使用 ejs 模板语言来做到这一点?
我在EJS官方网站和sails网站上都找不到任何相关信息。
到目前为止我天真地尝试过:
<% objects.forEach(function(object) { %>
<% if(object.someId == someValue) {%>
<%= object.name %>
<% break %> <!-- This raise an illegal statement exception -->
<% } %>
<% } %>
Run Code Online (Sandbox Code Playgroud)
以下代码按预期工作,但我正在寻找更干净的解决方案(如果有)
<% var found = false %>
<% objects.forEach(function(object) { %>
<% if(object.someId == someValue && !found) {%>
<%= object.name %>
<% found = true %>
<% } %>
<% } %>
Run Code Online (Sandbox Code Playgroud)