jquery ajax


$.ajax({
type: 'POST',
dataType:"json",
url: "https://localhost:44343/api/Values/getTel",
data:{
"tel":"13714390531"
},function(result) {
alert("返回值:" + result);
}
});

 

同步模式 async:false,(默认为异步)

 

成功案例


//判断宠物存不存在未结算的保障卡服务预售,如果存在,不让提交
var IsExist = "false";
$.ajax({
type: "GET",
url: "/AdvanceSale/IsExistAdvanceSale",
dataType: "json",
async: false,
data: {
"caseNum": CaseInfo.CaseNum,
},
success: function (result) {
IsExist = result.toString();
}
});

if (IsExist == "true") {
layer.msg("存在未结算的保障卡服务预售订单");
return;
}

 

 

同步的另一种写法

function submitMsg() {
var jsonData = $("form").serialize();
if (!validateForm()) {
return false;
}

if (true) {
var isExist = 0;
$.ajaxSettings.async = false;
$.ajax({
type: "post",
url: "@Url.Content("~/OutPatient/IsExistMember")",
data: { tel: $('#TEL').val(), id: $("#Id").val() },
async: false,
success: function (data) {
if (data != '') {
layer.msg('@HIS.MyResurces.GlobalResource.lbl_This_Mobile_already_exist');
isExist = 1;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 状态码
console.log(XMLHttpRequest.status);
// 状态
console.log(XMLHttpRequest.readyState);
// 错误信息
console.log(textStatus);
}
});
$.ajaxSettings.async = true;

if (isExist == 1) {
return false;
}
}

 

 

 

 

 

 

$.ajax({
type: 'GET',
dataType: "json",
url: "/AdvanceSale/IsExistAdvanceSale",
async:false,
data: {
"caseNum": CaseInfo.CaseNum,
}, function(result) {
if (result = "true") {
layer.msg("存在未结算的保障卡预售订单,不能继续购买保障卡预售");
$("#btnSubmit").removeAttr("disabled");
return;
}
}
});

 

 

 


$.post("https://localhost:44343/api/Values/getTel?tel=13714390531",function(result){
alert("返回值:" + result);
});

 

function tesr()
{
$.get("https://localhost:44343/api/Values/getTel?tel=13714390531",
function (data) {
alert("返回值:" + data);
});
}

 

 

<script type="text/javascript">
    function save(){
        var username=$("#username").val();
        var pwd=$("#pwd").val();
        var name=$("#name").val();
        var sex=$("#sex").val();
        var tel=$("#tel").val();
        if(username==null||username.length==0)
        {
            alert("用户名不能为空");
            return;
        }

        if(pwd==null||pwd.length==0)
        {
            alert("密码不能为空");
             return;
        }
        $.ajax({
            type:"POST",
            url:"/register",
            dataType:"json",
            data:{
                "username":username,
                "pwd":pwd,
                "name":name,
                "sex":sex,
                "tel":tel
            },
            success:function(data){
                if(data.Msg=="ok"){
                   alert("注册成功");
                }else{
                    alert(data.Msg);
                }
            },
            error:function(data){
                alert("服务错误");
            }
        });

    }

</script>

 

posted @ 2019-06-05 16:37  zhangzhiping35  阅读(82)  评论(0编辑  收藏  举报