将jQuery与Node.js一起使用时的基本错误 [英] Basic error when using jquery with nodejs

查看:112
本文介绍了将jQuery与Node.js一起使用时的基本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在项目中使用一些jquery,一旦尝试使用它,我就发现复制代码中出现错误,并且无法获得任何Google帮助

I'm trying to use some jquery in my project and as soon as I tried using it I came across an error in copied code and can't get any google help on it

 var jquery = require('jquery');
 var $ = jquery.create();
                ^
 TypeError: Object function ( w ) {
     if ( !w.document ) {
          throw new Error( "jQuery requires a window with a document" );
     }
     return factory( w );
 } has no method 'create'

长话短说

我正在尝试从某些HTML中获取纯文本.

I'm trying to get plaintext from some html I have.

我希望使用.text()函数,该函数应该可以做到这一点.

I hope to use .text() function which supposedly does that.

我得到的代码应该是:

console.log($(data).text());

推荐答案

您不能在服务器上使用jquery,因为它明确需要windowwindow.document.尝试 cheerio

You can't use jquery on server as it explicitly requires window and window.document. Try cheerio

这篇关于将jQuery与Node.js一起使用时的基本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆