简体   繁体   English

node.js html查询和解析

[英]node.js html querying and parsing

How do i make a dynamic search bar? 如何制作动态搜索栏? Do i need to use html methods? 我需要使用html方法吗? How can i make the bar dynamic? 如何使酒吧充满活力?

Hi, i just started learning node.js... while i never developed web applications. 嗨,我刚刚开始学习node.js ...而我从未开发过Web应用程序。 I don't want you to write the code, i just want you to point me to the right direction. 我不想让你写代码,我只是想让你指出正确的方向。

<form>
  <input type="text" name="search" placeholder="Search..">
</form>

Now, how do i get the information someone types in the search bar? 现在,如何获取某人在搜索栏中键入的信息? And what should i use to have the search bar display information without reloading the page? 在不重新加载页面的情况下,如何使用搜索栏显示信息?

Assuming you will not use any JS framework, the easiest way is to use a input with auto-complete feature. 假设您将不使用任何JS框架,最简单的方法是使用具有自动完成功能的输入。 One example: http://jqueryui.com/autocomplete/ 一个示例: http : //jqueryui.com/autocomplete/

A similar question: jQuery autocomplete with callback ajax json 一个类似的问题: 带有回调ajax json的jQuery自动完成

you could use socket.io to create a bidirectional connection with your server, and update your list each time something new pop's up 您可以使用socket.io与服务器建立双向连接,并在每次出现新的弹出窗口时更新列表

and if you're new to the server, take a look at my blog: https://mathieuauclairweb.wordpress.com/2017/05/02/how-to-make-a-nodejs-server-with-to-database-part-1/ 如果您是服务器新手,请看一下我的博客: https : //mathieuauclairweb.wordpress.com/2017/05/02/how-to-make-a-nodejs-server-with-to-database -第1部分/

I might add a tutorial on how to use socket.io this afternoon 我可能会在今天下午添加有关如何使用socket.io的教程

You have to use both JavaScript(jQuery) client-side code to make AJAX calls on 'keyup' handler and server-side PHP (or whatever language you use) routine to handle that AJAX call and answer it with JSON array. 您必须同时使用JavaScript(jQuery)客户端代码在“键”处理程序和服务器端PHP(或您使用的任何语言)上进行AJAX调用,以处理该AJAX调用并使用JSON数组进行应答。

If your search will return only plain text results, then you can check aria-autocomplete on the Internet. 如果搜索仅返回纯文本结果,则可以在Internet上检查aria-autocomplete There are plenty examples. 有很多例子。 In this method your server answer should contain a JSON array. 在这种方法中,您的服务器答案应包含JSON数组。 In a very similar way you can also populate <option> tags in a <select> . 同样,您也可以在<select>填充<option>标签。

If you dig much more without using aria-autocomplete you can make your own custom-styled display of answers. 如果在不使用aria-autocomplete情况下进行更多挖掘,则可以显示自己的自定义样式的答案。 You can take a look at my site http://www.zahranvane.com/ (only in Bulgarian language, sorry). 您可以浏览我的网站http://www.zahranvane.com/ (仅保加利亚语,对不起)。 There is a search field in the header. 标头中有一个搜索字段。 Type some number (like 511) and you will see matching results in a poping div. 输入一些数字(例如511),您会在弹出的div中看到匹配的结果。 To achieve this approach the server-side script returns formatted HTML which replaces the content of the poping div . 为了实现此方法,服务器端脚本返回格式化的HTML,该HTML替换弹出div的内容。

As @user3429660 advice you use jquery autocomplete. 作为@ user3429660建议,您可以使用jquery自动完成功能。

Create a function who call a webservice that you have defined in your nodejs with express for example. 例如,创建一个函数,该函数调用您在nodejs中定义的Web服务。 the web service return data in JSON to the function and the view is updated with jquery Web服务将JSON中的数据返回给该函数,并使用jquery更新视图

1) What you are looking for is getting the value out of the input: 1)您正在寻找的是从输入中获取价值:

Get the value in an input text box 在输入文本框中获取值

2) Not reloading page -> look into AJAX (many tutorials online...) 2)不重新加载页面->查看AJAX(许多在线教程...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM