zoukankan      html  css  js  c++  java
  • ajax POST跨域请求完美解决

    方式:

    js前端请求:

    function getOcrInfo(imageData){
    $.ajax({
       url: 'http://localhost:8080/LSWS/ws/ocr/getWebImageRecognitionJsonStringByBase64Image',
       type: 'post',
       dataType:'json',
       //async:false,
       data: {
            "imageData" : imageData
       },
       success:function(data){
          if(data.flag==0){
           var name=decodeURIComponent(data.name);
       var position=decodeURIComponent(data.position);

          }else{
          FR.Msg.alert("错误提示","获取识别结果失败,请重试!");
          } 
          
       },
       error:function(data){
           FR.Msg.alert("错误提示","获取识别结果失败,请重试!");
       }
    });

    服务器后端:

    @RequestMapping(value="/getWebImageRecognitionJsonStringByBase64Image", method = RequestMethod.POST)
    @ResponseBody
    public String getWebImageRecognitionJsonStringByBase64Image(HttpServletRequest request,HttpServletResponse response,String imageData) {
    String result = "";
    //System.out.println(imageData);
    try{
    WebImageRecognition gr = new WebImageRecognition();
    result = gr.getWebImageRecognitionJsonObjectByBase64Image(imageData);

    response.addHeader("Access-Control-Allow-Origin", "*");   //用于ajax post跨域(*,最好指定确定的http等协议+ip+端口号)
    response.setCharacterEncoding("utf-8");
    //response.getWriter().write(result);
    //response.getWriter().close();
    }catch(Exception e){
    e.printStackTrace();
    logger.error("getGeneralRecognition:"+e);
    result = "{"flag":"1","errorMessage":"server change error at OcrController!"}";
    }
       return result;
    }

  • 相关阅读:
    如何用conda安装软件|处理conda安装工具的动态库问题
    用 Anaconda 完美解决 Python2 和 python3 共存问题
    转录组数据库介绍
    突变注释工具SnpEff,Annovar,VEP,oncotator比较分析--转载
    BioConda--转载
    生信软件的好帮手-bioconda--转载
    一些WGS健康体检网站和公司
    基于R进行相关性分析--转载
    R语言 sub与gsub函数的区别
    Docker安装
  • 原文地址:https://www.cnblogs.com/lykbk/p/232442332423432432fgjhfghfgghf.html
Copyright © 2011-2022 走看看