使用Ajax和Node.js的简单按钮单击示例?(Simple button click example with Ajax and Node.js?)
我是Ajax和Node.js + Express的新手。 在这一点上,我试图弄清楚如何通过按钮与前端和后端进行通信。
我在HTML页面上有一个按钮,我想用它从后端调用函数并将文本输出到客户端。
以下是我根据需要拼凑的内容,但我正在寻找一个如何做到这一点的例子。
这一切都发生在/ page上
index.hjs文件
<button class="btn btn-success" onclick="install()">Install</button> // Client Side Ajax Script <script> $('button').click(function () { $.post('/page', {data: 'blah'}, function (data) { console.log(data); }); }, 'json'); </script>
app.js文件
app.post('/page', function (req, res, next) { calling.aFunction(); res.write('A message!'); });
这些是我需要的所有部件以及需要编辑哪些部件才能使此功能正常工作?
I am new to both Ajax and Node.js + Express. At this point I am trying to figure out how to communicate with both the front and back end through buttons.
I have a button on an HTML page which I would like to use to call a function from the backend and output text to the client.
Here is what I've pieced together for what I need but I am looking for an example on how this could be done.
This is all happening on /page
index.hjs file
<button class="btn btn-success" onclick="install()">Install</button> // Client Side Ajax Script <script> $('button').click(function () { $.post('/page', {data: 'blah'}, function (data) { console.log(data); }); }, 'json'); </script>
app.js file
app.post('/page', function (req, res, next) { calling.aFunction(); res.write('A message!'); });
Are these all the parts that I need and what needs to be edited to get this functionality to work?
原文:https://stackoverflow.com/questions/27158186
最满意答案
query.setParameterList("types", types); ^--
这应该做到这一点。
query.setParameterList("types", types); ^--
This should do it.
相关问答
更多-
HQL NOT运算符问题(HQL NOT operator issue)[2019-07-06]
这个对我有用: UPDATE Model m SET m.flag = !m.flag WHERE m.id = :id 和C#代码: var query = container.Resolve().CreateQuery(hql); query.SetParameter("id", 1); query.ExecuteUpdate(); It works for me: UPDATE Model m SET m.flag = !m.flag WHERE m.id = :id ... -
HQL中的常量枚举值(constant enum value in HQL)[2023-10-25]
首选的方法是将参数添加到查询中,并将枚举实例作为参数值传递,但如果您没有(或不能)使其成为参数化查询,则仍然可以使用String concatenation这个: public static final String venueQuery = "select distinct v from package.Venue v " + "" + "WHERE v.venueType = '" + VenueType.VOUCHER_PROVIDER.na ... -
解组parcelable数组时ClassCastException(ClassCastException when unmarshelling parcelable array)[2023-08-18]
你可以做类似这样的事情。其中p是你的可列表。 最后将位图列表转换回数组。 ListpList = Arrays.asList(p); ArrayList bList = new ArrayList (); for(Parcelable px : pList){ bList.add((Bitmap)px); } You can do something like this.Wher ... -
HQL IN运算符,枚举类ClassCastException的Array(HQL IN operator, Array of Enums ClassCastException)[2022-10-31]
query.setParameterList("types", types); ^-- 这应该做到这一点。 query.setParameterList("types", types); ^-- This should do it. -
HQL在运算符和参数中(HQL in operator and parameters)[2022-03-20]
:ids将是一个空的Guid数组,不是吗? 你问NHibernate给你的用户身份证是在一个非初始化的Guid数组中。 :ids would be an empty Guid array, wouldn't it? You're asking NHibernate to give you users where the id is inside a non-initialized array of Guid. -
您必须在构造函数中为ptr保留内存。 Array::Array (int size ){ //default constructor size = (size > 0 ? size : 10); ptr = new int [size]; // ADD THIS LINE for (int i = 0; i < size; i++) ptr[ i ] = 0; //initial values } 您的代码还有一些其他问题不 ...
-
枚举的运算符(operator for enums)[2024-02-05]
我不能说我曾经想过这样一个算子 - 依靠枚举值的排序会非常脆弱。 您可以轻松使用开关: switch (f) { case Fruit.Apple: myValue = fnApple(); break; case Fruit.Mango: myValue = fnMango(); break; case Fruit.Orange: myValue = fnOrange(); break; default: throw new ArgumentOutOfRangeExcept ... -
您可以使用REGEX解决问题,例如: REGEXP_LIKE('Hello world', 'Hello', 'mars') = 1 所以你可以替换你的查询: select ... where c.clientId = ? and c.vehicleReg1 like ? or c.vehicleReg2 like ? 在这里使用此查询: SELECT ... WHERE c.clientId = ? and REGEXP_LIKE(?, c.vehicleReg1, c.vehicleReg2) = ...
-
我找到了解决方案。 以这种方式编写HQL有效: select r from Role r where (r.Permissions & :param) > 0 I found a solution to this. Writing the HQL this way works: select r from Role r where (r.Permissions & :param) > 0
-
NHibernate hql元组结果(NHibernate hql tuple result)[2023-05-06]
是的,你可以,像: // The new Tuple(foo, bar) constructor Type constructor = typeof(Tuple ).GetConstructors()[0]; 接着 .SetResultTransformer(Transformers.AliasToBeanConstructor(constructor)); 在.List()之前 附录 我查看了我的代码(因为我已经在一两年前完成了这个:)),我注意到我更喜欢 Typ ...