Tag: ajax

使用datatable和node.js

我正在尝试使用jQuery数据表与Node.js. 这是我的代码HTML <button id="btnSearch" type="submit" class="btn btn-responsive"><i class="icon-search"></i>&nbsp;Search</button> <div class="box-body table-responsive no-padding"> <div id="tableContainer"> <table class="table table-hover" id="dataTables1"> <thead> <tr> <th class="text-left">base</th> <th class="text-left">base1</th> </tr> </thead> <tbody></tbody> </table> </div> <div class="text-center"> <img id="loading-image" src="../dist/img/loading_spinner.gif" style="display: none;" /> </div> </div> 这里是脚本代码 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> $("#btnSearch").click(function () { RefreshTable("#dataTables1"); }); function RefreshTable(tableId) { table = $(tableId).dataTable(); […]

使用node.js将值传递给代理页面

我有这个代码从客户端网站获取值: var server = ws.createServer(function(conn){ console.log("New Connection"); //on text function conn.on("text", function(str){ /* here i was to take that value in the str and pass it to html file which is path "agent/index.html"*/ }); }).listen(process.env.PORT, process.env.IP); 我想在agent / index.html文件中使用这个str值,并用它做一些事情。 这个str值来自于一个使用websockets的远程用户网站,现在我想把这个值传递给代理,这个代理立即回复它,它是一个实时聊天应用程序。 请检查评论。

无法连接Firebase数据库到Express.js服务器

大家下午好,我试图将我的快递服务器连接到我的Firebase数据库时遇到一些麻烦。 我正在做一个应用程序,使API调用我的快递服务器,反过来从我的客户端发送的信息使api调用这个晕api。 从那里从晕的服务器给我回来的信息被送回到我的快递服务器,它给我的客户端对象填充DOM。 上面所描述的一切,我已经得到了工作,耶,但现在我想要合并一个火力点数据库,事情并不完美。 我想要能够做的是添加更多的function与我的应用程序。 所以当这个API调用是从我的快递服务器( app.js )到晕的服务器,我想发送数据到我的firebase数据库,而不是回到客户端。 对我来说,在实践中,取而代之的是我从halo那里得到的数据对象,我现在只是把它称为晕,因为它更容易,并将其发送到我的firebase数据库。 从那里我将使用数据库来填充DOM。 正如我前面提到的,在实践中这certificate要困难得多。 我需要首先使用firebase,因为我需要添加CRUDfunction到这个应用程序,所以只是不使用它是不可能的。 目前运行我的服务器时,我运行nodemon src / app.js后在命令行中收到此错误: /Users/MMac/Desktop/haloApp/src/app.js:28 var dbReference = new Firebase("https://haloapp-5cfe2.firebaseio.com/"); ^ TypeError: Firebase is not a function at Object.<anonymous> (/Users/MMac/Desktop/haloApp/src/app.js:28:20) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:968:3 基于这个错误,我在想,我不需要正确的文件的Firebase,但我不知道哪一个包括。 我安装了firebase的节点包,我刚才读的教程只是使用var Firebase […]

Noodle.js安装程序/ jQuery过程(Web Scraping帮助!)

我已经通过npm install安装了noodle.js,这就是我现在的代码。 但是,当我运行这个文件(noodleTest.js)在terminal:节点noodleTest.js,我得到以下错误:jQuery.getJSON不是一个函数。 我已经看了大多数关于这个问题的堆栈溢出答案,并找不到修复。 通过http://noodlejs.com提供的例子,它在控制台中返回一个数组,但是当我试图运行这个代码片段时,我收到一个错误。 任何帮助表示赞赏。 var noodle = require('noodlejs'), jQuery = require ('jquery'); var query = { url: 'http://google.com/search?q=javascript', type: 'html', selector: 'h3.r a', extract: 'text' }, uriQuery = encodeURIComponent(JSON.stringify(query)), request = 'http://example.noodlejs.com/?q=' + uriQuery + '&callback=?'; // Make Ajax request to Noodle server jQuery.getJSON(request, function (data) { console.log(data[0].results); }); 编辑 :我试着按照给出的例子 http://%20github.com/dharmafly/noodle#noodle-as-a-node-module ,并使用noodlejs.com运行的例子,但我不知道如何读取数据,或如何提取对象中的内容。 […]

Loopback:通过ajax发布一个对象数组

我正在努力与使用Ajax的环回问题。 我尝试通过jQuery函数.ajax()一个对象的数组,但我只是根本不能。 服务器总是给我一个422错误(不可处理的实体)。 好奇的是:我可以使用GUI资源pipe理器或命令行完成相同的请求。 我有两个模型:通过hasMany / belongsTo关系关联的Nemo和PendingUpdates(我已经截断了它们,使其更具可读性): // nemo.json { "name": "Nemo", "base": "PersistedModel", "properties": { "id": { "type": "Number", "id": true, "required": false, "generated": true } }, "relations": { "pendingUpdates": { "type": "hasMany", "model": "PendingUpdate", "foreignKey": "nId" } } } 和 // pending-update.json { "name": "PendingUpdate", "base": "PersistedModel", "properties": { "id": { "type": "Number", […]

JavaScript / Nodejs:ajax POST请求不传递对象到后端

我试图发布一个JSON对象到我的服务器,但是当我控制日志req.body它显示一个空的对象。 这是我的代码: var submitRecipe = () => { let recipe = {alias: null, description: null, instructions: null}; recipe.alias = document.getElementById('alias').value; recipe.description = document.getElementById('description').value; recipe.instruction = document.getElementById('instructions').value; postRequest("/createrecipe", recipe, (xhr) => { console.log("Hello!" + JSON.parse(xhr.responseText)); }) }; var postRequest = (url, data, callback = undefined) => { xhr.onreadystatechange = () => { //Call a function when […]

Express js – 如何从ajax调用得到响应?

我试图发送表单数据到服务器端使用ajax(发送用户名),并在服务器端执行SQL查询并将结果传回给我的模板(EJS)。 在我的服务器端(ajaxTest.js) router.post('/', function(req, res){ console.log(req.body); var query = connection.query("select * from account where username='" + req.body.username+ "'",function (err,result) { console.log(query.sql); if (err) { console.error(err); return; } console.error(result); res.send("Result "+JSON.stringify(result)); }); }); 在我的模板(ajaxTest.ejs) $(document).ready(function () { $("#submit").on("submit",function (e) { e.preventDefault(); data = {}; data.username = 'user101'; $.ajax({ type: 'POST', data: JSON.stringify(data), contentType: 'application/json', url: 'http://localhost:3000/ajaxtest', […]

PhoneGap环境variables与开发环境中的AJAX数据服务有关吗?

我们正在制作一个PhoneGap应用程序,并尝试使用数据服务,如下所示: $.post(rooturl + '/data/something', { a: 1 }, (res) => {}); 问题:当应用程序在PhoneGap上运行时,它是一个没有自定义服务器后端的单页应用程序。 这意味着我没有办法通过某种环境指示器来更改rooturl,并将其指向本地NodeJS开发服务器数据服务,而不是生产服务器。 换句话说,我怎么能在客户端的Javascript检测是否正在开发环境中运行,以适当地设置适当的根url(开发/生产)?

使用$ .get定期轮询Express服务器

有一台带服务器时间发生器的Express服务器。 生成的时间被发送到客户端页面gtm.hbs 。 我如何从客户端页面定期轮询服务器? 我正在寻找一个Ajax解决scheme。 以下是存储在\routes\getTime.js的服务器端代码: module.exports = { sendCurrentUTCTimeString: function(req, res, next) { var currentUTCTime = new Date(); var currentUTCHours = currentUTCTime.getUTCHours(); var currentUTCMinutes = currentUTCTime.getUTCMinutes(); var currentUTCSeconds = currentUTCTime.getUTCSeconds(); currentUTCHours = ( currentUTCHours < 10 ? "0" : "" ) + currentUTCHours; currentUTCMinutes = ( currentUTCMinutes < 10 ? "0" : "" ) […]

JavaScript不能从networking驱动器工作

我试图运行下面的文件。 它在本地驱动器上运行时运行得非常好,但如果将其放在networking驱动器上,则不再有效。 任何想法,为什么这可能是? 下面是我试图运行的代码。 它从这里使用pivottable: https : //github.com/nicolaskruchten/pivottable 。 <!DOCTYPE html> <html> <head> <title> Demo</title> <!– external libs from cdnjs –> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <!– PivotTable.js libs from ../dist –> <link rel="stylesheet" type="text/css" href="../dist/pivot.css"> <script type="text/javascript" src="../dist/pivot.js"></script> <style> body {font-family: Verdana;} </style> <!– optional: mobile support with jqueryui-touch-punch –> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script> […]