AJAX

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。

AJAX 不是新的编程语言,而是一种使用现有标准的新方法。

AJAX 最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容。传统的网页(不使用 AJAX)如果需要更新内容,必需重载整个网页面。

<script type="text/javascript" language="JavaScript">
    function ajaxProcess(type) {
        var extparam="0";
        if(type=="S2" || type=="S1"){
            extparam=$("#txtS2Shard").val();
        }
        if(type=="M1"){
            extparam=$("#txtM1Shard").val();
        }
        if(extparam=="")extparam="0";
        $.ajax({
            url: "ajaxRequest",
            type: "POST",
            async: false,
            data: {"requsettype": type,"extparam":extparam},
            success: function (msg) {
                alert(msg)
            },
            error: function (ex) {
                alert(ex.responseText);
            }
        });
    }
</script>

controller:

@RequestMapping(value = "ajaxRequest", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public String ajaxDatas(@RequestParam String requsettype, @RequestParam String extparam) {
原文地址:https://www.cnblogs.com/twoheads/p/10275726.html