zoukankan      html  css  js  c++  java
  • JSONP 跨域解决办法

    <%@ 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>
  • 相关阅读:
    单链表的基本操作--c++
    剑指Offer-- 替换空格
    华为机试题-字符串分隔
    Leetcode 98. Validate Binary Search Tree
    树的层次遍历的几种方法
    Camera Path插件的使用
    3d 人物残像
    gameUnity 0.15 beta 网络游戏框架
    gameUnity 0.15alpha 网络游戏框架
    gameUnity 网络游戏框架
  • 原文地址:https://www.cnblogs.com/a198720/p/4111143.html
Copyright © 2011-2022 走看看