首页 > 代码库 > jsonp 后台返回注意事项

jsonp 后台返回注意事项

前端代码

<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
var time = ‘2017-03-01‘;
var money = 300.15;
var remark = ‘aaa‘;
$.ajax({
    url: ‘http://localhost:8084/TeamAccount/AddOne‘,
    type: ‘get‘,
    dataType: ‘jsonp‘,
    data: {
        time: time,
        money: money,
        remark: remark
    },
    success: function (data) {
        console.log(data);
    } 
});

</script>

后台返回

        try (PrintWriter out = response.getWriter()) {
            
            String callback = request.getParameter("callback");    
            String retStr = callback + "({\"name\":\"beidao\",\"age\":25});";
            /* TODO output your page here. You may use following sample code. */
            out.println("retStr");
        }

注意: retStr的格式“callback+(json串);

 

jsonp 后台返回注意事项