0 0

spring 3.1 mvc json jquery ajax得不到数据 5

spring 3.1.1
jquery 1.8.0
web.xml
  <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>biservice</display-name>
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:log4j.xml</param-value>
	</context-param>
	<context-param>
		<param-name>log4jRefreshInterval</param-name>
		<param-value>60000</param-value>
	</context-param>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext.xml</param-value>
	</context-param>
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>json</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/servlet.xml</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>json</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>
</web-app>

servlet.xml
  <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"

	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	<context:component-scan base-package="com.ft.bi.controller" />
	<context:annotation-config />
	<mvc:annotation-driven />
</beans>

Controller
@Controller
public class BiController {
	@Autowired
	private BiService biService;

	@RequestMapping(value = "/search")
	@ResponseBody
	public List<UvModel> getAnalysisDatas(@RequestParam String start,
			@RequestParam String end, @RequestParam int prjid,
			@RequestParam int ty) {
		return biService.getUvModels(start, end, prjid, ty);

	}

ajax代码

  $.ajax({
			url : 'http://localhost:8080/biservice/search?start=2013-03-01&end=2013-03-02&prjid=333&ty=1',
			dataType : 'json',
			success : function(data) {
				alert(data);
			},
			error: function(jqXHR, textStatus, errorThrown) {
            alert("Issue fetching the JSON: "
                + textStatus + " "
                + errorThrown + " !");
        }
		});

	 
    }



主要问题:
  1、在浏览器访问 如果没有插件,会下载json内容
  2、ajax访问 alert error no Transport
  3、firebug查看ajax请求状态为200,但没有响应项和JSON项
  4、直接用firefox访问、firebug查看
     响应 内为返回数据,JSON内为放回数据
  
2013年4月18日 11:25

1个答案 按时间排序 按投票排序

0 0

采纳的答案

1、在浏览器访问 如果没有插件,会下载json内容   是IE还是都是?
  2、http://localhost:8080 和 你地址栏地址一样吗 是同一个域吗? 即地址栏中地址和这个前缀一模一样  是不是跨域了??

2013年4月18日 11:47

相关推荐

Global site tag (gtag.js) - Google Analytics