Tag: jsonp

JSONP以服务器端语言作为Javascript调用

我一直试图使用JSONP通过客户端调用(在不同的端口上)从服务器获取JSON对象。 但是,因为我的服务器是使用Node.js和Express在JavaScript中实现的,所以我一直无法在服务器上使用Javascript来查找JSONP上的大部分网站,因为我发现大多数网站使用php来获取服务器端代码。 我相信这个问题是关于如何在callback方面设置url的,这对我来说是新的。 在服务器上: //Setting up server stuff var express = require('express'), app = express.createServer(); app.use(express.logger()); //Making a connection to the mongoDB to get the data that I want to display in the JSON object new Db('prism', new Server("127.0.0.1", 27017, {auto_reconnect: false}), {}).open(function(err, db) { app.get('/getData', function(req, res) { console.log('JSONPCALLBACK CALLED WITH RETURNDATA PASSED IN; […]

在发送jsonp请求phonegap时捕获响应

我写的应用程序通过手机服务器端我写nodejs exports.login = function(request, response) { var keys = Object.keys(request.query); request.body= JSON.parse(keys[1]); Accounts.findOne({ name : request.body.name }, function(err, docs) { if (!docs) { response.json('{"error": "user-not-found"}'); } else { console.log("docs: ", docs); Accounts.validatePassword(request.body.password, docs['hashedPass'], docs['salt'], function(error, res) { if (error) { response.json(error); } if (res) { generateToken(request.body.name, request.body.device, function(res) { if (res) { response.json('{"token": "' + […]

JSONP在node.js中未定义,使用.send会导致意外的令牌错误

我在我的node.js函数中使用JSONP: this.send(JSON.stringify({ type: 'hello', username: this.data('username'), friends: friends })); 但是,它给了我一个意想不到的令牌“:”错误(我没有看到在JSON中)。 在阅读这篇文章之后: jsonp中的'Uncaught SyntaxError:Unexpected token:' 我发现它可能是一个JSON / JSONP的问题。 所以我改变了我的代码: this.jsonp(JSON.stringify({ type: 'hello', username: this.data('username'), friends: friends })); 但是,它说这没有方法“jsonp”。 我不能使用发送,因为我在客户端使用jsonp。 这很奇怪,因为我可以在任何地方使用jsonp,但是在这里。 这里是user.js文件中的一些函数。 User.prototype.send = function(code, message, callback) { this._send('listener', code, message, callback); }; User.prototype._send = function(type, code, message, callback) { if(!message && typeof code != 'number') { […]

对蒸汽市场的GET请求错误

我试图做一个GET请求来获取蒸汽市场上的单个项目的物品价格信息。 这里是我正在使用的确切的angularJS脚本: <script> var app = angular.module('csgo', []); app.controller('MainCtrl', function($scope, $http) { $http.jsonp("http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29").success(function(response) { $scope.values = response; console.log(response); }); }); </script> 当我尝试在浏览器中执行此操作时,我得到: Uncaught SyntaxError: Unexpected token : ?currency=3&appid=730&market_hash_name=StatTrak™ P250 | Steel Disruption (Factory New):1 在我的Chrome浏览器控制台中。 然后点击错误信息中的链接(?currency = 3&appid = 730&market_hash_name = StatTrak™P250 | Steel Disruption(Factory New):1) 这需要我的一条线是: {"success":true,"lowest_price":"1,09€ ","volume":"348","median_price":"1,01€ "} 所以我实际上得到的信息,但它给出了一个错误,并强调红色的JSON响应。 有人知道这个问题吗? 我使用nodejs,express和angular。 编辑: 我尝试了一个不同的url: […]

node.js表示jsonp的返回types

不知道为什么,但我的快速应用程序是res.jsonp返回一些奇怪的东西,像这样的: /**/ typeof jsonp1406719695757 === 'function' && jsonp1406719695757({"published":true,"can_add_to_cart":true,"updated_at":"2014-01-[…snip…] 相反只有这个: jsonp1406719695757({"published":true,"can_add_to_cart":true,"updated_at":"2014-01-[…snip…] 我不明白为什么。 有任何想法吗?

有没有办法parsingjsonp服务器端angular度通用?

我有一个网站build立了angular2,它从第三方服务器请求数据。 我也使用angular度通用来呈现服务器端的页面。 问题在于:parsingjsonp依赖于dom操作,这在服务器端是不可用的。 所以我只能得到没有数据的静态页面。 有没有办法parsing服务器端的jsonp?

使用jQuery – JSONP从Vagrant VM上托pipe的第三方Node.js服务器获取数据

我有一个Node.js服务器监听本地主机:3000 作为一个黑盒子 , 输出我想加载到本地网站的用户界面 。 用jQuery编写的消费服务是: $('.my_selector').click(function(){ $.ajax({ url: ':3000/', method: "POST", success: function(data) { $("#content").append(data); }, error: function(jqXHR, textStatus, errorThrown) { alert('error ' + textStatus + " " + errorThrown); } }); }); 不是直接访问页面,而是加载内容并将其附加到#content 。 问题是代码不起作用。 编辑: 如果我设置localhost:3000到url我得到XMLHttpRequest Exception : jquery.min.js:4 XMLHttpRequest cannot load localhost:3000/. Cross origin requests are only supported for protocol schemes: […]

从Sencha Touch 2到外部服务器的跨域更新

尝试创build同步到Node.js服务器的Sencha-Touch-2应用程序; 下面的代码。 服务器使用同一IP上的另一个端口,所以这是跨域的。 (服务器使用Mongoose与MongoDB后端对话(未显示)) 如图所示使用JSONP代理可以从服务器读取数据,但在写入时会中断: “JSONP代理只能用于读取数据” 。 我猜JSONP代理编写器configuration只是写查询,不用于写同步(保存)。 Sencha文档声明,即使在Sencha论坛中讨论了跨域Ext.Ajax/Ext.data.Connection ,但是Ajax代理不能跨域, http : //www.sencha.com/forum/showthread。 PHP?17691-跨域-Ext.Ajax的-Ext.data.Connection 我已经find了几种方法来做(跨域)JSON发布(例如, 移动应用程序使用Sencha的触摸 – JSON请求生成语法错误 ),但不知道如何将其作为一个作家在同步我的商店的代理作家。 Sencha Touch:创build/更新function的ScriptTagProxy url似乎提供了指针,但这是ajax,显然不适合跨域。 我一直在阅读这个论坛和其他地方几天,但我似乎被卡住了。 任何帮助将非常感激。 Node.js和restify服务器 var server = restify.createServer({ name: 'Server', key: fs.readFileSync(root+'/'+'privatekey.pem'), certificate: fs.readFileSync(root+'/'+'certificate.pem') }); server.use(restify.bodyParser()); server.use(restify.queryParser()); function getMessages(req, res, next) { Model.find(function (err,data) { res.setHeader('Content-Type', 'text/javascript;charset=UTF-8'); res.send(req.query["callback"] + '({"records":' + JSON.stringify(data) + '});'); […]

快速API res.jsonp返回双重callback

我有一个运行在8080端口的Express服务器 app.get('/api', function (req, res) { res.jsonp('user API is running'); }); 我打开一个浏览器窗口 http://ec2-54-226-27-72.compute-1.amazonaws.com:8080/api?callback=hello 浏览器中的响应是 hello && hello("user API is running"); 为什么有2个hellos? 这是来自Express的适当的JSONP响应,并将由客户端正确处理?

为返回JSONP的Restful api节点HTTP请求

我正在尝试使用node.js将服务器端调用到restful API。 使用JSONP(JS函数中的JSON容器)返回正在返回的错误,这似乎是节点http.get(options,callback)API的核心。 节点或任何模块能否从JSONP返回JSON对象? 示例JSONP请求: http : //www.linkedin.com/countserv/count/share? url= http : //techcrunch.com/2012/01/29/turning-two-founderscard-pulls-back-the-curtain-在其通会员制社区的创业者/