jsonp数据传递问题!!!

Lh5225972 2014-01-02 01:42:46
用jsonp向后台传递数据后,经过整理,后台java代码如何写能把后台整理的参数传给前台?
$.ajax({
type:"get",
url:"http://127.0.0.1:8080/payment/selectInfo",
dataType:"jsonp",
jsonp: "callback",
jsonpCallback:"selectInfo",
data:{
customerId:customerId
},
success:function (data) {
alert("data"+data);
},
error:function () {
alert("查询数据错误!");
}
});
...全文
223 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Java_OneByte 2014-01-02
  • 打赏
  • 举报
回复
PrintWriter out;
Java_OneByte 2014-01-02
  • 打赏
  • 举报
回复
// 打开输出
	public void openWriter(HttpServletResponse resp) {
		try {
			resp.setCharacterEncoding("utf-8");
			resp.setContentType("text/html;charset=utf-8");
			out = resp.getWriter();
		} catch (IOException e) {
			MyUtil.printInfo("---------------------------openWriter IOException--------------------------------------- ");
			e.printStackTrace();
		}
	}

	// 关闭输出
	public void closeWriter() {
		if (out != null) {
			out.flush();
			out.close();
		}
	}
out.print("要输出的信息。。。");//这个就是respone
pandorawff 2014-01-02
  • 打赏
  • 举报
回复
楼主,你是不是想要说的是Ext的request请求跨域的问题 ?如果是,,可以换一种方式解决方案,让request先请求本地action,然后在action里面模拟post/get请求。
licip 2014-01-02
  • 打赏
  • 举报
回复
引用 3 楼 rui888 的回复:
你封装成json 格式 地址栏敲 url 你看下数据结构。 //http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>
            xxx
        </title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
        </script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                $.ajax({
                    type: "get",
                    async: false,
                    data: {                        
                    },
                    url: "http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US",
                    dataType: "jsonp",
                    jsonp: "callback",
                    success: function(json) {                        
                        for (var e in json.postalcodes[0]) {                       
                            document.write(e + "--->" + json.postalcodes[0][e]+"<br/>");                            
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }

                });

            });
        </script>
    </head>
    
    <body>
      
    </body>

</html>
+1
yuyeyi 2014-01-02
  • 打赏
  • 举报
回复
{[name:11]}
tony4geek 2014-01-02
  • 打赏
  • 举报
回复
你返回json的格式的数据就好了。确认你的url 返回json。
Lh5225972 2014-01-02
  • 打赏
  • 举报
回复
我现在是后台的返回不知道该如何去写。。。写的返回都收不到
tony4geek 2014-01-02
  • 打赏
  • 举报
回复
你封装成json 格式 地址栏敲 url 你看下数据结构。 //http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>
            xxx
        </title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
        </script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                $.ajax({
                    type: "get",
                    async: false,
                    data: {                        
                    },
                    url: "http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US",
                    dataType: "jsonp",
                    jsonp: "callback",
                    success: function(json) {                        
                        for (var e in json.postalcodes[0]) {                       
                            document.write(e + "--->" + json.postalcodes[0][e]+"<br/>");                            
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }

                });

            });
        </script>
    </head>
    
    <body>
      
    </body>

</html>
Lh5225972 2014-01-02
  • 打赏
  • 举报
回复
比如我后台组织一个Sring 的flag,要把这个单一的返回到前台呢?
tony4geek 2014-01-02
  • 打赏
  • 举报
回复
jsonp, 返回的格式要是json 。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧