ajax调用实例

Posted @circle

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(‘获取信息失败‘);
        }
    });

只是记录一下~

以上是关于ajax调用实例的主要内容,如果未能解决你的问题,请参考以下文章

AJAX的一个简单实例,跨域的解决,使用JQuery来进行ajax的调用

调用片段活动错误无法实例化活动。无法转换为 android.app.Activity

使用 Jquery 的同步“Ajax”调用似乎不起作用

html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。

AJAX调用完成后的消息提示框

为啥保守光栅化无法为某些三角形调用片段着色器?