Tag: jquery

阅读Node.JS中的AJAX postvariables(使用Express)

我试图得到我的节点应用程序中发送的ajax文章的值。 使用这篇文章作为指导,我到目前为止: 在节点中: var express = require('express'); var app = express(); var db = require('./db'); app.get('/sender', function(req, res) { res.sendfile('public/send.html'); }); app.post('/send_save', function(req, res) { console.log(req.body.id) console.log(req.body.title); console.log(req.body.content); res.contentType('json'); res.send({ some: JSON.stringify({response:'json'}) }); }); app.listen(3000); 在AJAX方面: $('#submit').click(function() { alert('clicked') console.log($('#guid').val()) console.log($('#page_title').val()) console.log($('#page-content').val()) $.ajax({ url: "/send_save", type: "POST", dataType: "json", data: { id: $('#guid').val(), title: $('#page_title').val(), […]

如何将项目Expressjs与jQuery-File-Upload整合?

jQuery-File-Upload与Nodejs很好地协作,但我发现很难与Expressjs集成。 有什么build议么? 感谢您的关注。 PD: https : //github.com/blueimp/jQuery-File-Upload

XMLHttpRequest无法加载。 请求的资源上没有“Access-Control-Allow-Origin”标题。 因此,原产地不得进入

我使用Apache HTTPD服务器托pipe客户端文件 http://ipaddress:8010/ 和我的Nodejs服务器上运行http://ipaddress:8087 当我发送邮件请求,然后显示以下错误 XMLHttpRequest cannot load http://ipaddress:8010/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ipaddress:8087' is therefore not allowed access. 我的客户端代码是: $.ajax({ type: "POST", url: "http://ipaddress:8010", data: {name:"xyz"}, success: function(){ alert("success"); }, dataType: "json" }); 我的服务器端是: response.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); response.setHeader('Access-Control-Allow-Credentials', true); 选项允许仍然是行不通的任何人都可以build议究竟是什么问题? 我在服务器端收到请求,但无法发送任何响应。 提前致谢 […]

Node.js没有方法'sendHeader'

Node.js没有方法'sendHeader' 安装副本是从git clone git://github.com/joyent/node.git 安装在ubunti lucid服务器中作为Amazon EC2 AMI文件。 通过命令输出简单地说你好。 但是,当输出到浏览器,它无法正常工作。 伙计们,有任何想法来解决它? 我希望使用node.js,但似乎还没有准备好生产使用。 ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ node hello_world_server.js Server running at http://localhost:8080/ /home/ubuntu/Desktop/node/test3/hello_world_server.js:5 response.sendHeader(200, {"Content-Type": "text/html"}); ^ TypeError: Object #<ServerResponse> has no method 'sendHeader' at Server.<anonymous> (/home/ubuntu/Desktop/node/test3/hello_world_server.js:5:14) at Server.emit (events.js:45:17) at HTTPParser.onIncoming (http.js:1081:12) at HTTPParser.onHeadersComplete (http.js:87:31) at Socket.ondata (http.js:980:22) at Socket._onReadable (net.js:654:27) at IOWatcher.onReadable [as callback] (net.js:156:10) ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ […]

获取对象的名称作为string没有评估

下面的代码做我想要的,但我想避免eval 。 在Javascript中有一个函数根据string中定义的名称查找对象吗? myobject = {"foo" : "bar"} myname = "myobject"; eval(myname); 一些上下文:我正在使用这个应用程序,其中dom中的大量节点具有html5 data-object属性,该属性在处理函数中用于连接回模型。 编辑:myobject既不是全局的,也不是本地的,它是在处理程序的父框架之一中定义的。

在Angular JS Module中传递和获取DOM元素值

我是Angular JS的新手 我有一个HTML页面,加载这样一个JS文件 <script type="text/javascript" src="components/adf-widget-iframe/dist/adf-widget-iframe.min.js"></script> 该文件(adf-widget-iframe.min.js)内容如下 ! function() { "use strict"; angular.module("adf.widget.iframe", ["adf.provider"]).config(["dashboardProvider", function(e) { e.widget("iframe", { title: "iframe", description: "Embed an external page into the dashboard", templateUrl: "{widgetsPath}/iframe/src/view.html", controller: "iframeController", controllerAs: "iframe", edit: { templateUrl: "{widgetsPath}/iframe/src/edit.html" }, config: { height: "420px" } }) }]).controller("iframeController", ["$sce", "config", function(e, r) { r.url && (this.url = […]

酶如果React组件需要jQuery,则会引发错误

我试图用Enzyme的describeWithDOM()和mount()来testing一个React组件的行为。 但是,当组件导入jQuery我得到这个错误: 错误:jQuery需要一个包含文档的窗口 我知道Enzyme使用引擎盖下的jsdom,我一直以为jsdom照顾窗口和文件。 但我似乎无法find如何让这些工作在一起。 testing代码如下所示: import chai, {expect} from 'chai'; import Select from './Select'; import React, {createElement} from 'react'; import {describeWithDOM, mount} from 'enzyme'; describe('UI Select', () => { //more shallow tests here describeWithDOM('User Actions', () => { it('Toggles the .ui-options menu on button click', () => { const wrapper = mount(<Select {…baseProps} />); […]

node.js html-pdf转换问题,文件回来腐败

我正在尝试创build一个应用程序,它将采用一个使用jquery get请求填充的html文件。 我正在做一个http获取请求来获取html,将string传递给pdf.create函数,并使用生成的缓冲区通过电子邮件发送PDF文件。 这似乎处理和发送文件作为电子邮件附件,但是,当我尝试打开文件时,我收到一个错误,说该文件已损坏。 code that convert html document to pdf: var options = { host: 'localhost', path: '/salesorder/' + orderid, port: '3000' }; http.request(options, function(response){ let buffer = ''; response.on('data', function (chunk) { buffer += chunk; }); response.on('end', function () { pdf.create(buffer, { directory: "tmp" }).toBuffer(function(err, newbuffer){ if (err){ reject(err); } if (Buffer.isBuffer(newbuffer)){ resolve(newbuffer); […]

在Web服务器上安装节点js

我使用node.js和socket.io创build了一个简单的聊天应用程序,它在localhost:3000中工作 但是,我想把它放在我自己的网站上。 我不知道如何在web服务器上安装node.js包。 我有Mac。 你有什么想法,怎么做?

jQuery.ajax#get后意外的令牌冒号JSON

我在nodejs上创build了一个以JSON格式返回数据的极简API。 但每次我尝试做一个Ajax#调用,并通过我的API作为URL,我会得到一个错误,并从Chrome判断,我得到一个"Unexpected token :"错误; 这里是nodejs + express中的服务器代码: var http = require( 'http' ), express = require( 'express' ), app = express(), server = http.createServer( app ); app.get( '/', function( req, res ) { console.log( 'req received' ); res.setHeader('Content-Type', 'application/json'); res.end( JSON.stringify({ Name : "Tom", Description : "Hello it's me!" }) ); }); server.listen(3000, function() { […]