sessionstorage本地数据库存储和ajax提交后台的数据接口

//下一步调用时触发的函数
function queren() {
    var i = 0, emilArray = [], phoneArray = [], phoneNumber = 0, emilNumber = 0;
    //获取的token存入会话中
    var storage = window.sessionStorage;
    if (!window.sessionStorage) {
        alert("浏览器不支持sessionStorage");
    } else {
        console.log(storage.data);
    }
    //用,分割输入的字符产并将结果存入数组中
    var textEmilValue = $('.text-email').val();
    var textEmilArray = [];
    var textEmilArray = textEmilValue.split(",");
    for (i = 0; i < textEmilArray.length; i++) {
        if (!isNaN(textEmilArray[i])) {

            phoneArray[i] = textEmilArray[i];
            phoneNumber = 1;
        } else if (isEmail(textEmilArray[i])) {
            emilArray[i] = textEmilArray[i];
            emilNumber = 1;
        }
    }
    //调用上传的接口,传输数据给后台。
    if (phoneNumber == 1) {
        console.log(storage.company_Id);
        $.ajax({
            url: 'http://192.168.191.3:8080/WorkCloud/Company?m=invite',
            dataType: 'json',
            type: 'POST',//post方式
            data: {      //发送给后台的数据
                'token':storage.token,
                'company_id':storage.company_Id,
                'mobile':phoneArray,
                'email':emilArray
            },
            success: function (data) {
                if (data.status == 1) {
                    console.log(data.info);
                } else {
                    console.log(data.info);
                }
            }
        })
    }
    if (emilNumber == 1) {
        $.ajax({
            url:'http://192.168.191.3:8080/WorkCloud/Company?m=invite',
            dataType:'json',
            type:'POST',
            data: {
                'token':storage.token,
                'company_id':storage.company_Id,
                'mobile':phoneArray,
                'email':emilArray
            },
            success: function (data) {
                if (data.status == 1) {
                    console.log(data.info);
                } else {
                    console.log(data.info);
                }
            }
        })
    }
}
//判断是否是邮箱
function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return 1;
    }
    else {
        return 0;
    }
}

你可能感兴趣的:(js高级程序设计)