首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsonp数据传递有关问题!

2014-01-19 
jsonp数据传递问题!!!用jsonp向后台传递数据后,经过整理,后台java代码如何写能把后台整理的参数传给前台?$

jsonp数据传递问题!!!
用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("查询数据错误!");
           }
});
[解决办法]
你封装成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>

热点排行