$.ajax() 方法
一:js代码
$(function () {
$("#login").click(function () {
$.ajax({
type: "POST", //请求方式
url: "http://localhost:80/cdw-be/index.php/Admin/login", //发送请求的地址
data: {
uname: "123",
pwd: "123"
}, //发送到服务器的数据
//dataType: "json", //预期服务器返回的数据类型
error: function (data) {
alert("connection error");
},
//请求成功后调用的回掉函数 两个参数1、服务器返回 根据dataType参数进行处理后的数据 2、描述状态的字符串
success: function (data) {
alert(data); //警告框返回获取的数据
window.location.href = "../../index.html"; //本窗口跳转其他页面
}
});
});
});url :http://localhost:80/cdw-be/index.php/Admin/login
数据:
uname 123
pwd 123
附上: (php -- 数据库配置信息)
<?php
return array(
//'配置项'=>'配置值'
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'test', //<span style="font-family: Arial, Helvetica,
'DB_USER' => 'root', // 用户名
'DB_PWD' => '123456', // 密码
'DB_PORT' => '3306', // 端口
'DB_PREFIX' => 'car_', // 数据库表前缀
'DB_FIELDTYPE_CHECK' => false, // 是否进行字段类型检查
'DB_FIELDS_CACHE' => true, // 启用字段缓存
'DB_CHARSET' => 'utf8', // 数据库编码默认采用utf8
);附录: 登陆代码


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>login</title>
<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
<script>
$(function () {
$("#login").click(function () {
$.ajax({
type: "POST", //请求方式
url: "http://localhost:80/cdw-be/index.php/Admin/login", //发送请求的地址
data: {
uname: "123",
pwd: "123"
}, //发送到服务器的数据
//dataType: "json", //预期服务器返回的数据类型
error: function (data) {
alert("connection error");
},
//请求成功后调用的回掉函数 两个参数1、服务器返回 根据dataType参数进行处理后的数据 2、描述状态的字符串
success: function (data) {
alert(data); //警告框返回获取的数据
window.location.href = "../../index.html"; //本窗口跳转其他页面
}
});
});
});
</script>
</head>
<body>
<div>
<p>
<label for="username">用户名</label>
<input type="text" id="username" />
</p>
<p>
<label for="password">密码</label>
<input type="text" id="password" />
</p>
<p>
<button type="button" id="login">登陆</button>
</p>
</div>
</body>
</html>View Code 相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
时光如瑾雨微凉 2020-07-19
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05