ajax异步通讯

前端之家收集整理的这篇文章主要介绍了ajax异步通讯前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前台代码:

$.ajax({
         url:'../file/isFolderNameExist.do',//url:'${ctx}/index.jsp',cache:false,type:'post',dataType:'html',data:{ 
                hyid:folderid,userids:foldername,contentType: "application/x-www-form-urlencoded;charset=utf-8"
            },success:function(html){
                alert("html:"+html)
                 
            }
        })

备注:

1 如果参数内容中文,请添加属性contentType,这样需要做编码转换了

contentType: "application/x-www-form-urlencoded;charset=utf-8",

后台代码

public void isFolderNameExist(HttpServletRequest request,HttpServletResponse response){
        String folderId = request.getParameter("folderId") == null ? "" : request.getParameter("folderId");
        String folodername = request.getParameter("folodername") == null ? "" : request.getParameter("folodername");
        int iret = folderManager.isFolderNameExist(folderId,folodername);
        try {
            response.setCharacterEncoding("UTF-8");
            PrintWriter pw = response.getWriter();
            pw.write(iret);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
原文链接:https://www.f2er.com/ajax/166518.html

猜你在找的Ajax相关文章