zoukankan      html  css  js  c++  java
  • Ajax向Controller发送请求并接受数据需要注意的一个细节

    想用Ajax想向Controller发送请求和接收返回的字符等等。Controller中要使用@ResponseBody注解。

    <script type="text/javascript">
        function loadXMLDoc()
        {
            if (window.XMLHttpRequest){
                
                var request = new XMLHttpRequest();
                var url = "http://localhost:8080/TestJson/ajaxController/testAjax?time=" + new Date();
                
            //open中的第三个参数要用true,表示异步的
                request.open("GET", url, true);
                request.send();
                
                request.onreadystatechange = function(){
                    if(request.readyState == 4 && request.status == 200){
                        document.getElementById("myDiv").innerHTML=request.responseText;
                    }
                }
            }else{
            }
        }
    </script>

    ----

    @RequestMapping(value="testAjax", method=RequestMethod.GET)
        public @ResponseBody String testAjax(@RequestParam(name="time") String time, ModelAndView modelAndView) throws InterruptedException
        {
    //        Thread.sleep(8000);
            System.out.println("请求发送到服务器");
            System.out.println(time);
            
            modelAndView.setViewName("testAsync");
            String link = "<a href='http://www.baidu.com'>www.baidu.com</a>";
            return link;
        }
  • 相关阅读:
    Ranorex发布2.3版本支持Flex4
    TestComplete基础教程
    2009年缺陷跟踪和测试管理工具使用情况调查报告
    软件自动化测试资源列表
    TestComplete资源列表
    分治算法
    画表格蓝桥杯
    分红酒蓝桥杯
    “硬币方案”蓝桥杯
    微生物增值蓝桥杯
  • 原文地址:https://www.cnblogs.com/GooPolaris/p/7919854.html
Copyright © 2011-2022 走看看