<%@ 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>
时间: 2024-12-23 15:49:18