我在Windows 7上运行了全新的node.js安装,我正在尝试运行一个非常基本的JQuery脚本,命名为a.js:
require("jquery");
$().jquery;
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不会与JQuery一起运行,给我一个TypeError:
C:\Users\Ian>node a.js
C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10
window.XMLHttpRequest.prototype.withCredentials = false;
^
TypeError: Cannot read property 'prototype' of undefined
at create (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10:26)
at C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9435:18
at Object.<anonymous> (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9437:2)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (C:\Users\Ian\a.js:1:63)
Run Code Online (Sandbox Code Playgroud)
我通过谷歌发现了一些有关此错误的错误报告,其中大部分都建议降级JQuery.但是,当我这样做时,我只会得到一个不同的错误.以下是JQuery 1.6.3:
C:\Users\Ian>node a.js
module.js:340
throw err;
^
Error: Cannot find module 'location'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at create (C:\Users\Ian\node_modules\jquery\node-jquery.js:6:33)
at C:\Users\Ian\node_modules\jquery\node-jquery.js:9065:18 …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行节点脚本和html页面,但是我一直收到错误消息。我尝试运行的脚本是:
node script.js page.html
Run Code Online (Sandbox Code Playgroud)
script.js文件具有以下内容:
var argv = require('optimist').argv,
$ = require('jquery'),
fs = require('fs');
var file = argv._[0];
var html = fs.readFileSync(file, 'UTF-8');
$(html).find('p').each(function(index) {
var content = $(this).html();
console.log('Paragraph ' + (index + 1) + ': ' + content);
});
Run Code Online (Sandbox Code Playgroud)
我的page.html具有以下代码:
<html>
<body>
<p>Apple</p>
<span>Unrelated</span>
<p>Orange</p>
<div>Steak</div>
<p>Banana</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的packages.json文件内容如下:
{
"name": "paragraphs",
"version": "1.0.0",
"main": "script.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"optimist": "0.3.4",
"jquery": "1.7.3"
},
"author": …Run Code Online (Sandbox Code Playgroud) 当我在IE7或IE8中运行我的应用程序时,window.XMLHttpRequest的值是未定义的,是否有任何我必须在IE7中启用才能使其工作.
谢谢
我正在尝试测试xml文件是否有标签" <group>"
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", "xmlfile.xml", false);
xmlhttp.send(null);
xml = xmlhttp.responseXML.documentElement;
var thegroup = xml.getElementsByTagName('group')[0];
if (!group) {
alert('No <group> in the XML: ' + xml);
return;
} else {
alert(xml + 'have a <group> tag');
}
Run Code Online (Sandbox Code Playgroud)
即使我的xml文件有标签" <group>"的结果总是负的,而变量" thegroup"是不确定的.
" xml"给我"[对象元素]"
我的错误在哪里?
PS:我只对webkit感兴趣,我现在不关心IE,Opera或Firefox.
编辑:这是我的实际代码
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
<title>xmltest</title>
<script type="text/javascript">
function init() {
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", "xmlfile.xml");
xmlhttp.send(null);
xmlhttp.onreadystatechange = callbackFunction; …Run Code Online (Sandbox Code Playgroud)