ajax调用实例

海尔订阅按钮的例子:

    $(".dingyue").click(function () {
        if (istrsidssdssotoken()) {//cookie 中的是否登录
            if (null == proid || "undefined" == proid) {
                return;
            }
            if (null == urlxmlpath || "undefined" == urlxmlpath) {
                return;
            }
            var productcate = "";
            if (urlxmlpath.indexOf("/cooling/") > -1) {
                productcate = "冰箱";
            } else if (urlxmlpath.indexOf("/laundry/") > -1) {
                productcate = "洗衣机";
            } else if (urlxmlpath.indexOf("/air_conditioners/") > -1) {
                productcate = "空调";
            } else if (urlxmlpath.indexOf("/televisions/") > -1) {
                productcate = "彩电";
            } else if (urlxmlpath.indexOf("/kitchen_appliances/") > -1) {
                productcate = "厨房电器";
            } else if (urlxmlpath.indexOf("/kitchen/") > -1) {
                productcate = "整体厨房";
            } else if (urlxmlpath.indexOf("/water_heater/") > -1) {
                productcate = "热水器";
            } else if (urlxmlpath.indexOf("/small_applications/") > -1) {
                productcate = "生活小家电";
            } else if (urlxmlpath.indexOf("/computers/") > -1) {
                productcate = "电脑";
            } else if (urlxmlpath.indexOf("/lsdn/") > -1) {
                productcate = "历史电脑";
            } else if (urlxmlpath.indexOf("/digital/") > -1) {
                productcate = "手机数码";
            }
            var countryname = "cn";

            jQuery.ajax({
                type: "post",
                dataType: "json",
                url: "/HaierFramework/haier/mycollection/addProductCollectionAsync.do",
                data: {
                    'productId': proid,
                    'productxmlpath': urlxmlpath,
                    'countryname': countryname,
                    'productcategory': productcate
                },
                success: function (returnResult) {
                    if (returnResult.isSuccess) {
                        if (returnResult.stutas == 2) {
                            $(".js_collect_head").html("");
                            $(".js_collect_head").html("您已经收藏过此产品");
                            var logintype = LoginType();
                            if (logintype == "haierCounts") {
                                $("#js_collect_threelogin").hide();
                                var userinfo = getuserinfo();
                                if (userinfo != "") {
                                    if (userinfo.indexOf(",") != -1) {
                                        var infoArray = userinfo.split(",");
                                        var emailtemp = infoArray[0];
                                        var teltemp = infoArray[1];
                                        var emailArray = emailtemp.split("=");
                                        email = emailArray[1];
                                        var telArray = teltemp.split("=");
                                        tel = telArray[1];
                                    } else {
                                        if (userinfo.indexOf("email") != -1) {
                                            var emailArray = userinfo.split("=");
                                            email = emailArray[1];
                                        } else if (userinfo.indexOf("tel") != -1) {
                                            var telArray = userinfo.split("=");
                                            tel = telArray[1];
                                        }
                                    }
                                }
                                $("#js_message_mail2").val(email);
                                $("#js_message_tel2").val(tel);
                            } else {
                                $("#js_collect_haierlogin").hide();
                            }
                            $(".js_btn_collect").click();
                        } else {
                            var logintype = LoginType();
                            if (logintype == "haierCounts") {
                                $("#js_collect_threelogin").hide();
                                var userinfo = getuserinfo();
                                if (userinfo != "") {
                                    if (userinfo.indexOf(",") != -1) {
                                        var infoArray = userinfo.split(",");
                                        var emailtemp = infoArray[0];
                                        var teltemp = infoArray[1];
                                        var emailArray = emailtemp.split("=");
                                        email = emailArray[1];
                                        var telArray = teltemp.split("=");
                                        tel = telArray[1];
                                    } else {
                                        if (userinfo.indexOf("email") != -1) {
                                            var emailArray = userinfo.split("=");
                                            email = emailArray[1];
                                        } else if (userinfo.indexOf("tel") != -1) {
                                            var telArray = userinfo.split("=");
                                            tel = telArray[1];
                                        }
                                    }
                                }
                                $("#js_message_mail2").val(email);
                                $("#js_message_tel2").val(tel);
                            } else {
                                $("#js_collect_haierlogin").hide();
                            }
                            $(".js_btn_collect").click();
                        }
                        //监控代码
                        collection_success();
                    } else {
                        gotoLogin();
                    }
                },
                error: function () {
                }
            });


        } else {
            gotoLogin();
        }
    })

最简单的例子:

 $.ajax({
        url:"/api/workflow/task!cancelAndAgreeOrDisagreeStep.do",
        dataType: 'json',
        type: 'post',
        data: {
            task_id: task_id
        },
        success: function success(data) {
            //成功后执行的动作
             
        },
        error: function error() {
            //alert('获取信息失败');
        }
    });

只是记录一下~

原文地址:https://www.cnblogs.com/circleone/p/7614518.html