使用jQuery的$ .get时出错我得不到。

时间:2020-12-10 14:21:46

It's simple:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>

<script src="jquery.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
        $.get("http://twitter.com/statuses/user_timeline/19092829.rss");
    });
</script>
</head>
<body>

</body>
</html>

In IE and Opera this works perfectly, but in FF 3.5, Chrome, and Safari I get a 400 Bad Request. Looking at the request using Fiddler2 and FireBug, something is replacing GET with OPTIONS. But in IE and Opera, it is still showing up as GET. I don't get it????

在IE和Opera中,这非常有效,但在FF 3.5,Chrome和Safari中我得到了400 Bad Request。使用Fiddler2和FireBug查看请求,有些东西正在用OPTIONS替换GET。但在IE和Opera中,它仍然显示为GET。我不明白????

EDIT: I feel like such an idiot for not even thinking of XSS policies. Thanks guys.

编辑:我觉得这样的白痴甚至没有考虑XSS政策。多谢你们。

2 个解决方案

#1


You can't $.get() from a different domain. Security issues.

你不能从另一个域$ .get()。安全问题。

You can go through a proxy script on your server though. You could use PHP or C# (.NET) to get the data for you and return it to your jQuery script.

您可以在服务器上浏览代理脚本。您可以使用PHP或C#(.NET)为您获取数据并将其返回到您的jQuery脚本。

#2


Your script has hit a permission denied error.

您的脚本遇到了权限被拒绝错误。

Browsers have a security feature that defines which URLs you can call. Calling a URL from different domain is usually not allowed, because it will open avenues for cross site scripting attacks.

浏览器具有一个安全功能,可以定义您可以调用的URL。通常不允许从不同域调用URL,因为它将为跨站点脚本攻击开辟途径。

jQuery have a solution called JSONP, but that depends on the other party supplying JSONP implementation.

jQuery有一个名为JSONP的解决方案,但这取决于提供JSONP实现的另一方。

For Twitter, I personally used this:

对于Twitter,我个人使用了这个:

$.getJSON('http://twitter.com/statuses/user_timeline/[username].json?count=10&callback=?', function(data) { });

#1


You can't $.get() from a different domain. Security issues.

你不能从另一个域$ .get()。安全问题。

You can go through a proxy script on your server though. You could use PHP or C# (.NET) to get the data for you and return it to your jQuery script.

您可以在服务器上浏览代理脚本。您可以使用PHP或C#(.NET)为您获取数据并将其返回到您的jQuery脚本。

#2


Your script has hit a permission denied error.

您的脚本遇到了权限被拒绝错误。

Browsers have a security feature that defines which URLs you can call. Calling a URL from different domain is usually not allowed, because it will open avenues for cross site scripting attacks.

浏览器具有一个安全功能,可以定义您可以调用的URL。通常不允许从不同域调用URL,因为它将为跨站点脚本攻击开辟途径。

jQuery have a solution called JSONP, but that depends on the other party supplying JSONP implementation.

jQuery有一个名为JSONP的解决方案,但这取决于提供JSONP实现的另一方。

For Twitter, I personally used this:

对于Twitter,我个人使用了这个:

$.getJSON('http://twitter.com/statuses/user_timeline/[username].json?count=10&callback=?', function(data) { });

相关文章