- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 jQuery 和 .ajax 调用来调用 bit.ly URL 缩短服务。
更新 我想知道这是否是跨域安全问题?我正在从 mysite.com
调用 bit.ly
<html><head>
<script type="text/javascript" src="http://www.twipler.com/settings/scripts/jquery.1.4.min.js"></script>
<script type="text/javascript">
jQuery.fn.shorten = function(url)
{
var resultUrl = url;
$.ajax(
{
url: "http://api.bit.ly/shorten?version=2.0.1&login=twipler&apiKey=R_4e618e42fadbb802cf95c6c2dbab3763&longUrl=" + url,
async: false,
dataType: 'json',
data: "",
type: "GET",
success:
function (json) { resultUrl = json.results[url].shortUrl; }
});
return resultUrl;
} ;
</script></head><body>
<a href="#"
onclick="alert($().shorten('http://amiconnectedtotheinternet.com'));">
Shorten</a> </body> </html>
这适用于 IE8,但不适用于 FireFox (3.5.9) 或 Chrome。在这两种情况下,“json”均为 null。
IE8 中的 header
GET http://api.bit.ly/shorten?ver..[SNIP]..dtotheinternet.com HTTP/1.1
Accept: application/json, text/javascript, */*
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0;
SLCC2; .NET CLR 2.0.50727; Media Center PC 6.0; InfoPath.2;
.NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Host: api.bit.ly
Connection: Keep-Alive
Chrome 中的 header
GET http://api.bit.ly/shorten?versio..[SNIP]..nectedtotheinternet.com HTTP/1.1
Host: api.bit.ly
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5
(KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
Origin: file://
Accept: application/json, text/javascript, */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
所以唯一明显的区别是 Chrome 正在发送“Origin: file://”,但我不知道如何阻止它这样做。
最佳答案
使用 Fiddler 验证请求的实际负载和 bit.ly 服务的响应。将 IE 请求/响应与 Chrome 请求/响应进行比较,找出不同之处。
我(疯狂)的猜测是,当 Firefox 和 Chrome 发送请求时,由于浏览器发出请求的方式不同,该服务会返回一条错误消息。特别是,您附加 url 参数的方式对我来说似乎有点可疑,为了以防万一,我会对它进行 url 编码。
更新: 所以 HTTP header 确实揭示了问题。 :-)
Origin header当用户代理想要建议网站该请求是跨源请求时添加。显然Chrome has added support最近对于这个标题。当然:
The details of the Origin header are still being finalized. We will update the implementation in Google Chrome as the specification evolves based on feedback from Mozilla and from the W3C and IETF communities at large.
您目前可能无法采取任何措施来阻止 Chrome 发送该 header 。顺便说一句,Origin
header 似乎是 Firefox 3.6 首次引入的,我怀疑您是运行所有最新、最好的浏览器的人之一。 :-)
顺便说一句,XMLHttpRequest
确实有跨域限制。所以,我想知道 jQuery.Ajax 是否没有使用新的 XDomainRequest
在 IE8 上而不是 XMLHttpRequest
。
但是回到您的问题 - 此时一切都表明唯一可用的解决方案是对您的站点进行 Ajax 调用并从您的服务器进行 bit.ly 调用。我知道这不是最佳选择...
关于jQuery .ajax 调用 bit.ly 在 IE 中返回结果,但在 FF 或 Chrome 中不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601315/
我正在解析一个 XML 文件,其中包含一些条目,如下所示: FF FF FF FF FF FF FF FF 我将它们保存到 HashMap现在我想转换 String我进入int[] . 但我不知道该怎
我有一个这样的数组: unsigned char array[] = {'\xc0', '\x3f', '\x0e', '\x54', '\xe5', '\x20'}; unsigned char a
输入的正则表达式应该是什么: FF a b FF 其中a和b可以是下面给出的任意组合- FF 1 2 FF FF A C FF FF F D3 FF FF EF 1C FF 我尝试使用 /(FF [a
作为我们的 rebase-heavy 工作流程的一部分,我希望在 master 分支上使用 merge 。特别是,我只想在主题分支重新基于最近的主提交时才 merge ,从而使任何 merge 成为快
在 Qt 项目中,我必须通过以下分隔符拆分 QString 壮举。 壮举。 专长 壮举 特色 特色。 特色 特色 我最好的尝试是 (?: [Ff]eat[.]? )|(?: [[Ff]eaturing
我的网络应用程序在接受上传的图像之前会根据文件扩展名检查前四个字节。一位同事向我展示了他 iPhone 上的图像,但这些图像被拒绝了。它们具有不同的第四个字节(e1 = 225,而不是预期的 e0 =
为什么我在 Firefox Mac 和 Firefox Windows 中有不同的换行行为。如何确保我在两个平台上有相同的换行符? 使用小数位对我来说很重要。 你可以看到我的示例代码和我的截图on J
请检查此屏幕截图! alt text http://img267.imageshack.us/img267/1391/difference.png 这是在 Linux FF(左侧)和 Windows
我有时想做一个--ff-only merge ,制表符完成有点尴尬,因为--ff存在。但是--ff是默认行为,我无法想象想要明确指定它。我可以制作 --ff --ff-only 的同义词?我知道我可以
我编写了一个 jQuery 脚本来检查浏览器高度并与内容面板的高度进行比较。如果面板大于窗口高度,则脚本会使所有内容变小。 它在 Chrome 和 Safari 中运行良好。在 Firefox 上它根
在 IE 中,您可以像以前的渲染引擎一样查看页面。您使用 9 并查看为 8、7、6。 如果这在 Firefox 中可行?我正在使用 FF7,我想看看网站在 3.6 中的显示方式。 这是可能的还是我需要
对我来说,一个典型的 git 工作流程是克隆一个远程存储库并使用 git pull 来保持它是最新的。我不想在 pull 时 merge 提交,所以我使用 --ff-only 选项。 我还为特色工作创
我们可以让 ff-find-other-file 在 ff-search-directories 列出的目录中递归搜索吗? 它不仅会在/usr/include 中搜索,还会在/usr/include/
我遇到了 Java Scripting API together with JavaScript 的问题在某些电脑上。分析转储文件后,我注意到“FF FF”在某些 PC 上被打印为“FD”。下面是代码
这个问题已经有答案了: Why don't flex items shrink past content size? (7 个回答) 已关闭 2 年前。 我们在桌面应用程序(例如 Web 应用程序)中
public class Ex51 { public static void main(String args[]) { Scanner input = new Scanner
这个问题在这里已经有了答案: Why don't flex items shrink past content size? (5 个答案) 关闭 2 年前。
我希望 git merge 默认为 --no-ff 并且 git pull 使用 --ff 当它 merge 获取的分支时。 有没有办法配置 git 自动执行此操作? 最佳答案 我建议设置 merge
假设我有一堆在 Linux 和 Firefox 上运行的 Selenium 测试。现在,我遇到了一些问题,我想查看 FF GUI 来调查这个问题。是否可以连接到服务器,即使用 VNC 查看器查看我的测
我正在使用 jquery 创建命名空间事件。当我使用以下带有 code=112 的函数(函数 bool=false)时,FF 中一切正常,并且 F1 键提交到我的函数,并且该事件不会冒泡以在新选项卡中
我是一名优秀的程序员,十分优秀!