当前位置 博文首页 > 程序员石磊:spring boot jquery ajax ie8解决跨域

    程序员石磊:spring boot jquery ajax ie8解决跨域

    作者:[db:作者] 时间:2021-08-08 22:22

    增加 crossDomain: true == !(document.all),

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>jQuery CORS in IE7 - IE10</title>
        <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script>
            $(document).ready(function () {
                $.ajax({
                    url: "http://dreamfactorysql.cloudapp.net/API/index.php",
                    dataType: "text",
                    async: true,
                    type:GET,
                    cache: false,
                    crossDomain: true == !(document.all),
                    success: function (data) {
                        alert(data);
                    }
                });
            });
        </script>
    </head>
    <body>
    IE7 thru IE10 CORS Example Using jQuery
    </body>
    

    增加 @CrossOrigin

    
    @RestController
    public class UserInfoController {
    
    
        @RequestMapping("/test")
        @CrossOrigin
        @ResponseBody
        Map test() {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("key","zltest");
            return map;
        }
    
        @RequestMapping("/login")
        ModelAndView login() {
            return new ModelAndView("login");
        }
    
    
    }
    
    
    cs