jsonp

AJAX跨域总结

三世轮回 提交于 2019-12-04 05:55:03
蚂蚁金服的实习即将结束,将知识总结一下。 我们这个项目前端使用antD,antD是采用React封装的一套组件库,目前开源 http://ant.design/ ,所有组件都是拿来即用,大大缩短了开发周期,强烈推荐。React是单页面应用,通过ajax与后台通信,而antD调试部署在8000端口,后台又是运行在另一个端口,前后台通信跨域。AJAX跨域一般有两种解决方法:CORS(跨域资源共享)和JSONP。 先来看看JSONP,本质原理利用script标签src属性可以跨域的特性,我们自己也可以去实现JSONP,动态添加删除script标签: function loadJs() { var script = document.createElement("script"); script.src = "http://xxxxxx/get/req"; document.body.appendChild(script); script.onload = function() { callback(); document.body.removeChild(script); } } 在AJAX中使用JSOP: $.ajax({ url: 'http://xxxxxx/get/req', cache: false, type: 'post', jsonp:'callback',

Single sign-on, multiple domains on same server, ruby on rails

梦想与她 提交于 2019-12-04 05:06:11
If I have a single server with multiple domains, what is the preferred method for implementing a single-sign-on solution on the same domain. I am currently using devise, have a few million cookies in place on separate domains, and am stuck. On top of just implementing SSO, I also need to migrate the various cookies to a central domain. Regarding the various servers, they only have one single page that requires me to show different states depending on whether or not the user is logged in. I have tried the following: CORS: pick one domain as the central auth hub. From all other domains make

How to use dataType: 'jsonp' but still have application/json in Accept header?

不羁的心 提交于 2019-12-04 03:54:52
问题 I want to access a REST service on another domain. If, in JQuery, I specify: dataType: 'json' it fails, as expected, since for cross-domain calls, JSONP must be used instead. When I change this to: dataType: 'jsonp' it is expected to work, but fails because the server expects application/json or application/xml or text/html , etc., but not */* , sent by the JSONP request. Is there a way to force JQuery to put application/json in Accept request header while doing a JSON request? 回答1: AFAIK

Why does a single Ajax call work fine, but consecutive Ajax calls fail?

百般思念 提交于 2019-12-04 03:53:13
Setup: I have a Datatable, whose each row is clickable. When a row is clicked, an ajax call is made which returns some data. Sometimes the ajax call takes a little time, depending on the amount of data being returned. It is all working fine. Problem: The problem occurs when the rows are clicked quickly, one after the other. In short, before the previous ajax call returns, if the row is clicked (i.e. a new ajax call is made), I get an error. Uncaught TypeError: Property 'callback' of object [object Window] is not a function (The ajax call returns a JSONP data) It looks like somehow the ajax

jQuery JSONP not calling the callback

南楼画角 提交于 2019-12-04 03:49:18
I am having some problem with jsonp and jquery. This is my code - var myCallback = function(data) { console.log(data); }; $.ajax({ url: my_url, type: 'GET', dataType: 'jsonp', jsonp: 'callback', jsonpCallback: 'myCallback' }); jQuery adds something like ?callback=myCallback&_=1340513330866 to my_url and the data returned from my_url is myCallback('abcd') - although in reality it will be returning some HTML code instead of the abcd . Problem: abcd is not logged in console through myCallback . So what am i doing wrong ? I was under the impression that the data returned will be executed as it is

PHP: Handling 'JSONP' output vs 'JSON', and its parsing?

你。 提交于 2019-12-04 03:27:56
问题 I am having a problem parsing 'jsonp' request with php's json_decode function. My questions is a. What is the use of call back function in 'jsonp', should i just trip that off, or am I suppose to use it in some manner. ? b. How can I rectify the syntax error received in 'jsonp' format ? Below I have given the code and the response that I get. 1. I request a sample url with PHP's curl $url = 'https://ssl.domain.com/data/4564/d.jsonp'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);

FireBug and monitoring JSONP cross-domain requests

浪尽此生 提交于 2019-12-04 02:50:15
This question is specific to the Firebug plugin for Firefox. The actual functionality works, but I lost my ability to monitor and debug it in Firebug. I had a website which used JSON to get data. In Firebug, I was able to monitor the JSON requests. It would show me each one of them, the headers, and the data that was returned. I needed to change the server to which I submitted my JSON requests. In order to get cross-domain JSON to work, I used JSONP with the callback=? method. I got the functionality to work. However, I cannot monitor and debug my JSONP requests now in Firebug. For the record,

JSONP To Acquire JSON From HTTPS Protocol with JQuery

放肆的年华 提交于 2019-12-04 02:17:16
I'm trying to acquire a JSON which is being sent from an https secure site, The client was hoping not to use any Server-side languages (the whole thing in Javascript) I've read that I must use JSONP in order to load a JSON from a secure site, when using the .ajax function from Jquery. My first question would be what format do I need to set this JSONP as? Right now my code looks like this: html =new Object(); html = $.ajax({ url: "https://my-secure.net", async: false, dataType: 'jsonp' }).responseText; //alert(html); alert("myObject is " + html.toSource()); console.log(html); However, nothing

跨域几种方式

让人想犯罪 __ 提交于 2019-12-04 02:01:06
一、什么是跨域 JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象。那什么是跨域呢,简单地理解就是因为JavaScript同源策略的限制,a.com域名下的js无法操作b.com或是c.a.com域名下的对象。 当协议、子域名、主域名、端口号中任意一个不相同时,都算作不同域 。不同域之间相互请求资源,就算作“跨域”。 例如: http://www.abc.com/index.html 请求 http://www.efg.com/service.php 。 有一点必须要注意: 跨域并不是请求发不出去,请求能发出去,服务端能收到请求并正常返回结果,只是结果被浏览器拦截了 。之所以会跨域,是因为受到了同源策略的限制,同源策略要求源相同才能正常进行通信,即协议、域名、端口号都完全一致。 大家可以参照下图,有助于深入理解跨域。 特别说明两点: 第一:如果是协议和端口造成的跨域问题“前台”是无能为力的。 第二:在跨域问题上,域仅仅是通过“URL的首部”来识别而不会根据域名对应的IP地址是否相同来判断。“URL的首部”可以理解为“协议, 域名和端口必须匹配” 。 二、什么是同源策略及其限制 同源策略限制从一个源加载的文档或脚本如何与来自另一个源的资源进行交互。这是一个用于隔离潜在恶意文件的关键的安全机制。 它的存在可以保护用户隐私信息,防止身份伪造等(读取Cookie)。

When is this JSON structure getting converted to all strings?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 23:35:22
问题 I am sending a JSON structure to my node/express server and saving the object into a database. The problem is that I send JSON with integers and booleans but everything gets saved as strings. Here is my node/express code: var express = require('express'); var app = express(); app.enable("jsonp callback"); app.use(express.bodyParser()); // allow cross origin scripting to get data from devices directly app.all('*', function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res