---
title: "jquery ajax 跨域"
author: "taoshi"
date: "2014-10-29T14:42:39Z"
tags: []
categories: ["Web前端"]
slug: "jquery-ajax"
draft: false
lastmod: "2014-10-29T14:42:39Z"
id: 2149257
url: "https://taoshi.iteye.com/blog/2149257"
---

```java

function testRemote(){
	 $.ajax({
			type : "get",
			async:false,
			url : "http://192.168.30.36:8080/JavaScriptTools/remoteServlet",
			data: {
				timeStamp: new Date().getTime(),
				password:"123456",
				loginName:"changchao"
			},
			dataType : "jsonp",
			jsonp: "callbackparam",//服务端用于接收callback调用的function名的参数
			jsonpCallback:"success_jsonpCallback",//callback的function名称
			success : function(json){
				alert(json);
				alert(json[0].name);
			},
			error:function(){
				alert('fail');
			}
		});
 		}


```



```java

response.setContentType("text/html");
		
		String callbackFunName = request.getParameter("callbackparam");
		
		response.getWriter().print(callbackFunName + "([ { 'name':'john'}])");
		
		response.getWriter().flush();
		
		response.getWriter().close();


```