首页 > Web开发 > 详细

JSONP 跨域解决办法

时间:2014-11-20 18:23:45      阅读:362      评论:0      收藏:0      [点我收藏+]
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 解决IE情况下不识别JSON对象的情况 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" />
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    //var url = "http://172.21.0.31:13131/solr/xml/select?q=*%3A*&wt=json&indent=true";
    //url = "http://172.21.0.31:13131/solr/gxdemo/mlt?mlt.interestingTerms=details&stream.body=世纪公园";
    url = "http://localhost:8080/solr/test4/select?q=%E7%99%BE%E5%BA%A6&wt=json&indent=true";
    $(function() {
        //1.getJSON 方式
        /*
         *    可以设置一些ajax的参数
         */
        $.ajaxSetup({
            cache : false,
            contentType : "application/json; charset=utf-8"
        });

        $.getJSON(url + "&json.wrf=?", function(data) {
            //console.log(JSON.stringify(data));
            $(#test).html(JSON.stringify(data));
            //alert(JSON.stringify(data));
        });

        /*
        //2.ajax 方式
        $.ajax({
             ‘url‘: url,
             contentType: "application/json; charset=utf-8", 
             cache:false,
             //‘data‘: {‘wt‘:‘json‘, ‘q‘:‘your search goes here‘},
             ‘success‘: function(data) { 
                 //console.log(JSON.stringify(data));
                 alert(JSON.stringify(data));
             },
             error : function() {
                  alert(‘1‘);
             },
             ‘dataType‘: ‘jsonp‘,
             ‘jsonp‘: ‘json.wrf‘
        });
         */
    });
</script>
</head>
<body>
    <div id="test"></div>
</body>
</html>

 

JSONP 跨域解决办法

原文:http://www.cnblogs.com/a198720/p/4111143.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!