aa

<?php
header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set('PRC');
$mysql_conf = array(
'host' => 'localhost',
'db' => 'mytest002',
'db_user' => 'root',
'db_pwd' => '123123',
);
$mysql_conn = @mysql_connect($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
if (!$mysql_conn) {
die("could not connect to the database:\n" . mysql_error());
// 诊断连接错误
}
mysql_query("set names 'utf8'");//编码转化
$select_db = mysql_select_db($mysql_conf['db']);
if (!$select_db) {
die("could not connect to the db:\n" . mysql_error());
}
$sql = "select * from ydyl_region;";
$res = mysql_query($sql);
if (!$res) {
die("could get the res:\n" . mysql_error());
}

while ($row = mysql_fetch_assoc($res)) {
}

$sql = "select id,name from ydyl_region where status=1 and parent_id=5002 limit 0,100;";
$res = mysql_query($sql);

// var_dump($myrow);
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<script type="text/javascript" src="./js/jquery-2.0.3.min.js"></script>
<body>
<form id="form1" onclick="mytest()">
<select name="sel" multiple >
<option value="北京">请选择城市</option>
<?php
while ($row = mysql_fetch_assoc($res)) {
?>
<option value="<?php echo $row['id'] ?>" name="<?php echo $row['name'] ?>" id="<?php echo $row['id'] ?>"><?php echo $row['name'] ?></option>
<?php } ?>
</select>
</form>

</body>
<script type="text/javascript">
function mytest(){

// alert('a');
$.ajax({
    url: '3.php',
    type: 'POST',
    dataType: 'json',
    // data: {username: $('#username').val()},
    data:$('#form1').serialize(),
    cache:false,
    success:function(data){
      alert('data');
    }
})

}
</script>

posted @ 2018-03-02 16:53  林间有风-邓  阅读(129)  评论(0编辑  收藏  举报