javascript

85 阅读1分钟

JQuery

ajax

小小demo

$('#finmaryCommentscore').on('click', function (e) {
    $.ajax({
        type: "GET",
        url: "/admin/selectTeacher",
        async: true,
        dataType: "html",//返回整合HTML
        // dataType: "json",//返回json格式设置
        // dataType: "text"
        data: {
            'comment_time':'final',
            'evaluateDetails':'true'
        },
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
           /* $("#rightBody").html(data);//刷新整个body页面的html*/
        },
        error: function () {
           /* alert("请求失败")*/
        }
    })
});

小小demo

 //点击登录按钮
    $('#loginBtn').on('click',function (e) {
        let userId=$('#userId').val();
        let password=$('#password').val();
        loginCheck(userId,password);
    })
    //检查用户名和密码是不是正确
    async function loginCheck(userId,password) {
        const res=await request({url:'/student/checkLogin',data:{student_id:userId,password:password},type:'GET'});
        if (res==='fail'){
            alert("用户名或密码错误");
            $('#password').val("");
            $('#password').focus();
        }else {
            $('#loginForm').submit();//表单提交
        }
    }