日期:2014-05-16  浏览次数:20361 次

如何用javascript实现跨域数据传递?
本帖最后由 WildGhost 于 2014-01-02 09:01:57 编辑
例如,个人网站通常都会嵌入一段google analytics的js代码
既然javascript不允许跨域访问,那这段js代码是怎么把用户访问或点击的信息传给google服务器的?

------解决方案--------------------
script动态加载google的页面,参数附加客户的动作

js无法直接操作跨域的iframe内容,ajax不能直接请求跨域页面,看你js要进行什么操作了,不是说所有跨域操作都不允许
------解决方案--------------------
有的允许了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>
            xxx
        </title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
        </script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                $.ajax({
                    type: "get",
                    async: false,
                    data: {                        
                    },
                    url: "http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US",
                    dataType: "jsonp",
                    jsonp: "callback",
                    success: function(json) {              &