[模拟回调] demo1模拟用字符串调用js函数 demo2模拟springmvc controller回调页面js函数

demo1.       模拟用字符串调用js 函数
function dataQuery() {
    var strFun = "testCallBack";
    var strParam = "param";

    //Create the function
    var fn = window[strFun];

    //Call the function
    fn(strParam);
}

function testCallBack(str) {
    alert(str);
}



demo2.       模拟springmvc controller回调js函数

controller
    @RequestMapping(/doCallback}
    @ResponseBody
    public String doCallback() throws IOException {
        
        // 上传文件
        String url = **;

        // 调用前端js回调函数
        return "<script type='text/javascript'>updatepropImgCallBack('" + url + "');</script>";
    }

js

function updatepropImgCallBack(url){
    alert('上传完成返回的url是'+url);
}
原文地址:https://www.cnblogs.com/fanlinglong/p/6553523.html