javascript js:使用ajax获取数据库数据(后端采用php) - &#34

📅 2026-12-01 👤 拼多多助力营销技巧 📂 拼多多助力 👁️ 183 次阅读

前端ajax部分

AllUnsigned.php

数据库查询部分

get_allunsign.php

参数引用:$_POST['action']

返回数据:echo json_encode($data);

//引入连接数据库部分

require_once 'get_db_conn.php';

$conn = db_connect();

//如果传递的参数action等于noread_info,就执行下面的操作

if ($_POST['action'] == 'noread_info') {

//查询表all_unsigned中status等于未读,并且info_user等于参数userinfo

$sql1 = "select * from all_unsigned where status = '未读' and info_user = '" . $_POST['userinfo'] . "'";

//连接模糊查询

if (isset($_POST['type1']) and $_POST['type1'] != '') { 拼多多帮助力入口

$sql1 .= " and type LIKE '%" . $_POST['type1'] . "%' ";

}

if (isset($_POST['order_number1']) and $_POST['order_number1'] != '') {

$sql1 .= " and order_number LIKE '%" . $_POST['order_number1'] . "%' ";

}

//连接顺序查询

$sql1 .= " order by creation_date desc ";

//执行数据库

$result1 = mysqli_query($conn, $sql1);

// 检查结果集是否存在

if (mysqli_num_rows($result1) > 0) {

//如果存在数据就放入$data变量

$data = [];

while ($row = mysqli_fetch_assoc($result1)) {

$data[] = $row;

}

//否则变量data等于0

} else {

$data = 0;

}

//输出返回值给请求的页面

echo json_encode($data);

}

推荐文章,javascript

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧