|
|
|
ติด ajax+jquery ตรงส่งค่า มานานหลายวันละครับ ช่วยที |
|
|
|
|
|
|
|
ลอง alert ค่า msg ดูครับว่ามันคืนค่ามาไหม
Code (PHP)
success: function(msg){
alert(msg);
|
|
|
|
|
Date :
2014-05-27 13:14:47 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่มีครับ
พลาดตรงไหนอะครับ
|
|
|
|
|
Date :
2014-05-27 13:38:14 |
By :
littlebeer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีโค้ดเต็ม ๆ ไหมครับ
|
|
|
|
|
Date :
2014-05-27 14:54:47 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
require 'connection/connection.php';
if($_SESSION['userid'] == "")
{
echo '<script type="text/javascript">window.location = "login.php"; </script>';
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Blank Page - SB Admin</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Add custom CSS here -->
<link href="css/sb-admin.css" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<?php include 'sidebar.php'; ?>
</ul>
<ul class="nav navbar-nav navbar-right navbar-user"> <!--แทบด้านบน -->
<?php include 'header.php'; ?>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1>รายการซ่อม</h1>
<ol class="breadcrumb">
<li><a href="index.php"><i class="icon-dashboard"></i> หน้าหลัก</a></li>
<li class="active"><i class="icon-file-alt"></i> รายการซ่อม</li>
</ol>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-2">
<img src="img/red.PNG" /> - ด่วน
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/green.PNG" /> - ปกติ
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/yellow.PNG" /> - อื่น ๆ
</div>
</div>
<br>
<form name="frm_list" method="post" action="<?=$_SERVER["PHP_SELF"];?>" id="form1">
<div class="table-responsive">
<?php
$strSQL = "SELECT
work_descrip.work_id,
work_descrip.book_num,
work_descrip.Number,
work_descrip.Date,
work_descrip.Time,
work_descrip.work_descrip,
work_type.Type_name,
priority.Pri_name,
place.Place_name,
department.Dep_name,
work_descrip.working,
`user`.fname,
`user`.lname
FROM
work_descrip
INNER JOIN work_type ON work_type.Type_id = work_descrip.TypeID_FK
INNER JOIN priority ON priority.Pri_id = work_descrip.PriID_FK
INNER JOIN place ON place.Place_id = work_descrip.PlaceID_FK
INNER JOIN department ON department.Dep_id = work_descrip.DepID_FK
INNER JOIN `user` ON work_descrip.work_id = `user`.work_id_FK
";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th>แผนก/ฝ่าย <i class="fa fa-sort"></i></th>
<th>วันที่/เวลา แจ้ง <i class="fa fa-sort"></i></th>
<th>ประเภทงาน <i class="fa fa-sort"></i></th>
<th>ชื่อผู้แจ้ง <i class="fa fa-sort"></i></th>
<th>อาคาร/สถานที่ <i class="fa fa-sort"></i></th>
<th>รายละเอียด <i class="fa fa-sort"></i></th>
<th>ผู้ดำเนินงาน<i class="fa fa-sort"></i></th>
<th>การดำเนินงาน<i class="fa fa-sort"></i></th>
</tr>
</thead>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
$_SESSION['ope'] = $objResult['operate_id_FK'];
?>
<tbody>
<?php
if ($objResult["PriID_FK"] == "1") {
$class = "danger";
}
elseif ($objResult["PriID_FK"] == "2"){
$class = "success";
}
elseif ($objResult["PriID_FK"] == "3"){
$class = "warning";
}
?>
<tr class="<?=$class ?>">
<td><?=$objResult["Dep_name"];?></td>
<td><?=$objResult["Date"]." / ".$objResult["Time"];?></td>
<td><?=$objResult["Type_name"];?></td>
<td><?=$objResult["fname"];?> <?=$objResult["lname"];?></td>
<td><?=$objResult["Place_name"];?></td>
<td><?=$objResult["work_descrip"];?></td>
<td> </td>
<?php
if ($objResult["working"] == "Y") {
$work = "img/ico_bifag.png";
}
else {
$work = "img/no.png";
}
?>
<td align="center">
<input type="hidden" id="id" name="id" value="<?= $objResult['work_id']; ?>">
<input type="hidden" id="status" name="status" value="N">
<input type="image" src="<?=$work ?>" id="submit" alt="Submit" align="absmiddle">
<span id="stat"></span>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
</form>
<?php
mysql_close($connect);
?>
</div>
</div>
</div><!-- /.row -->
</div><!-- /#page-wrapper -->
</div><!-- /#wrapper -->
<!-- JavaScript -->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat");
$("#stat").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id").val() + "&status=" + $("#status").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
</body>
</html>
Code (PHP)
<?php
include('connection/connection.php');
?>
<?php
if($_GET["status"]=='N') {
$strSQL = "UPDATE work_descrip SET working = 'Y' WHERE work_id = '".$_GET["id"]."' ";
echo 'OK';
}
else {
echo 'No';
}
$objQuery = mysql_query($strSQL) or die(mysql_error());
?>
|
|
|
|
|
Date :
2014-05-27 15:13:43 |
By :
littlebeer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองว่าได้ไหมครับ
Code (PHP)
<?php
require 'connection/connection.php';
if($_SESSION['userid'] == "")
{
echo '<script type="text/javascript">window.location = "login.php"; </script>';
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Blank Page - SB Admin</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Add custom CSS here -->
<link href="css/sb-admin.css" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<?php include 'sidebar.php'; ?>
</ul>
<ul class="nav navbar-nav navbar-right navbar-user"> <!--แทบด้านบน -->
<?php include 'header.php'; ?>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1>รายการซ่อม</h1>
<ol class="breadcrumb">
<li><a href="index.php"><i class="icon-dashboard"></i> หน้าหลัก</a></li>
<li class="active"><i class="icon-file-alt"></i> รายการซ่อม</li>
</ol>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-2">
<img src="img/red.PNG" /> - ด่วน
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/green.PNG" /> - ปกติ
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/yellow.PNG" /> - อื่น ๆ
</div>
</div>
<br>
<form name="frm_list" method="post" action="<?=$_SERVER["PHP_SELF"];?>" id="form1">
<div class="table-responsive">
<?php
$strSQL = "SELECT
work_descrip.work_id,
work_descrip.book_num,
work_descrip.Number,
work_descrip.Date,
work_descrip.Time,
work_descrip.work_descrip,
work_type.Type_name,
priority.Pri_name,
place.Place_name,
department.Dep_name,
work_descrip.working,
`user`.fname,
`user`.lname
FROM
work_descrip
INNER JOIN work_type ON work_type.Type_id = work_descrip.TypeID_FK
INNER JOIN priority ON priority.Pri_id = work_descrip.PriID_FK
INNER JOIN place ON place.Place_id = work_descrip.PlaceID_FK
INNER JOIN department ON department.Dep_id = work_descrip.DepID_FK
INNER JOIN `user` ON work_descrip.work_id = `user`.work_id_FK
";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th>แผนก/ฝ่าย <i class="fa fa-sort"></i></th>
<th>วันที่/เวลา แจ้ง <i class="fa fa-sort"></i></th>
<th>ประเภทงาน <i class="fa fa-sort"></i></th>
<th>ชื่อผู้แจ้ง <i class="fa fa-sort"></i></th>
<th>อาคาร/สถานที่ <i class="fa fa-sort"></i></th>
<th>รายละเอียด <i class="fa fa-sort"></i></th>
<th>ผู้ดำเนินงาน<i class="fa fa-sort"></i></th>
<th>การดำเนินงาน<i class="fa fa-sort"></i></th>
</tr>
</thead>
<?php
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
$_SESSION['ope'] = $objResult['operate_id_FK'];
?>
<tbody>
<?php
if ($objResult["PriID_FK"] == "1") {
$class = "danger";
}
elseif ($objResult["PriID_FK"] == "2"){
$class = "success";
}
elseif ($objResult["PriID_FK"] == "3"){
$class = "warning";
}
?>
<tr class="<?=$class ?>">
<td><?=$objResult["Dep_name"];?></td>
<td><?=$objResult["Date"]." / ".$objResult["Time"];?></td>
<td><?=$objResult["Type_name"];?></td>
<td><?=$objResult["fname"];?> <?=$objResult["lname"];?></td>
<td><?=$objResult["Place_name"];?></td>
<td><?=$objResult["work_descrip"];?></td>
<td> </td>
<?php
if ($objResult["working"] == "Y") {
$work = "img/ico_bifag.png";
}
else {
$work = "img/no.png";
}
?>
<td align="center">
<input type="hidden" id="id<?php echo $i ?>" name="id<?php echo $i ?>" value="<?= $objResult['work_id']; ?>">
<input type="hidden" id="status<?php echo $i ?>" name="status<?php echo $i ?>" value="N">
<input type="image" src="<?=$work ?>" id="submit<?php echo $i ?>" alt="Submit<?php echo $i ?>" align="absmiddle">
<span id="stat<?php echo $i ?>"></span>
</td>
</tr>
</tbody>
<script type="text/javascript">
$(document).ready(function()
{
$("#submit<?php echo $i ?>").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat<?php echo $i ?>");
$("#stat<?php echo $i ?>").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id<?php echo $i ?>").val() + "&status=" + $("#status<?php echo $i ?>").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit<?php echo $i ?>").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit<?php echo $i ?>").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
<?php
}
?>
</table>
</form>
<?php
mysql_close($connect);
?>
</div>
</div>
</div><!-- /.row -->
</div><!-- /#page-wrapper -->
</div><!-- /#wrapper -->
<!-- JavaScript -->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
|
|
|
|
|
Date :
2014-05-27 15:20:24 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้อะครับ -*-
|
|
|
|
|
Date :
2014-05-27 15:41:40 |
By :
littlebeer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใหม่ ๆ ครับ
Code (PHP)
<?php
require 'connection/connection.php';
if($_SESSION['userid'] == "")
{
echo '<script type="text/javascript">window.location = "login.php"; </script>';
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Blank Page - SB Admin</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Add custom CSS here -->
<link href="css/sb-admin.css" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<script src="js/jquery-1.10.2.js"></script>
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<?php include 'sidebar.php'; ?>
</ul>
<ul class="nav navbar-nav navbar-right navbar-user"> <!--แทบด้านบน -->
<?php include 'header.php'; ?>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1>รายการซ่อม</h1>
<ol class="breadcrumb">
<li><a href="index.php"><i class="icon-dashboard"></i> หน้าหลัก</a></li>
<li class="active"><i class="icon-file-alt"></i> รายการซ่อม</li>
</ol>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-2">
<img src="img/red.PNG" /> - ด่วน
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/green.PNG" /> - ปกติ
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="img/yellow.PNG" /> - อื่น ๆ
</div>
</div>
<br>
<form name="frm_list" method="post" action="<?=$_SERVER["PHP_SELF"];?>" id="form1">
<div class="table-responsive">
<?php
$strSQL = "SELECT
work_descrip.work_id,
work_descrip.book_num,
work_descrip.Number,
work_descrip.Date,
work_descrip.Time,
work_descrip.work_descrip,
work_type.Type_name,
priority.Pri_name,
place.Place_name,
department.Dep_name,
work_descrip.working,
`user`.fname,
`user`.lname
FROM
work_descrip
INNER JOIN work_type ON work_type.Type_id = work_descrip.TypeID_FK
INNER JOIN priority ON priority.Pri_id = work_descrip.PriID_FK
INNER JOIN place ON place.Place_id = work_descrip.PlaceID_FK
INNER JOIN department ON department.Dep_id = work_descrip.DepID_FK
INNER JOIN `user` ON work_descrip.work_id = `user`.work_id_FK
";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th>แผนก/ฝ่าย <i class="fa fa-sort"></i></th>
<th>วันที่/เวลา แจ้ง <i class="fa fa-sort"></i></th>
<th>ประเภทงาน <i class="fa fa-sort"></i></th>
<th>ชื่อผู้แจ้ง <i class="fa fa-sort"></i></th>
<th>อาคาร/สถานที่ <i class="fa fa-sort"></i></th>
<th>รายละเอียด <i class="fa fa-sort"></i></th>
<th>ผู้ดำเนินงาน<i class="fa fa-sort"></i></th>
<th>การดำเนินงาน<i class="fa fa-sort"></i></th>
</tr>
</thead>
<?php
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
$_SESSION['ope'] = $objResult['operate_id_FK'];
?>
<tbody>
<?php
if ($objResult["PriID_FK"] == "1") {
$class = "danger";
}
elseif ($objResult["PriID_FK"] == "2"){
$class = "success";
}
elseif ($objResult["PriID_FK"] == "3"){
$class = "warning";
}
?>
<tr class="<?=$class ?>">
<td><?=$objResult["Dep_name"];?></td>
<td><?=$objResult["Date"]." / ".$objResult["Time"];?></td>
<td><?=$objResult["Type_name"];?></td>
<td><?=$objResult["fname"];?> <?=$objResult["lname"];?></td>
<td><?=$objResult["Place_name"];?></td>
<td><?=$objResult["work_descrip"];?></td>
<td> </td>
<?php
if ($objResult["working"] == "Y") {
$work = "img/ico_bifag.png";
}
else {
$work = "img/no.png";
}
?>
<td align="center">
<input type="hidden" id="id<?php echo $i ?>" name="id<?php echo $i ?>" value="<?= $objResult['work_id']; ?>">
<input type="hidden" id="status<?php echo $i ?>" name="status<?php echo $i ?>" value="N">
<input type="image" src="<?=$work ?>" id="submit<?php echo $i ?>" alt="Submit<?php echo $i ?>" align="absmiddle">
<span id="stat<?php echo $i ?>"></span>
</td>
</tr>
</tbody>
<script type="text/javascript">
$(document).ready(function()
{
$("#submit<?php echo $i ?>").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat<?php echo $i ?>");
$("#stat<?php echo $i ?>").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id<?php echo $i ?>").val() + "&status=" + $("#status<?php echo $i ?>").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit<?php echo $i ?>").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit<?php echo $i ?>").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
<?php
}
?>
</table>
</form>
<?php
mysql_close($connect);
?>
</div>
</div>
</div><!-- /.row -->
</div><!-- /#page-wrapper -->
</div><!-- /#wrapper -->
<!-- JavaScript -->
<script src="js/bootstrap.js"></script>
</body>
</html>
|
|
|
|
|
Date :
2014-05-27 15:49:23 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้ว ๆ ขอบคุณมากเลยครับ :)
ยังไงช่วยอธิบายว่าทำไมมันถึงไม่ได้ในตอนแรกทีครับ
|
|
|
|
|
Date :
2014-05-27 16:56:28 |
By :
littlebeer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค้ดของคุณตรง
Code (PHP)
<?php
if ($objResult["working"] == "Y") {
$work = "img/ico_bifag.png";
}
else {
$work = "img/no.png";
}
?>
<td align="center">
<input type="hidden" id="id" name="id" value="<?= $objResult['work_id']; ?>">
<input type="hidden" id="status" name="status" value="N">
<input type="image" src="<?=$work ?>" id="submit" alt="Submit" align="absmiddle">
<span id="stat"></span>
</td>
มันอยู่ในลูป while ซึ่งเมื่อแสดงผลแล้ว จะเกิด input ที่ไอดีเหมือนกัน คือ name, status, submit หลายอัน
เมื่อคุณเขียน Jquery
Code (PHP)
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat");
$("#stat").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id").val() + "&status=" + $("#status").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
มันจะมองไม่ออก เนื่องจากมีไอดีที่เหมือนกันเยอะ ซึ่งในหน้าหนึ่ง ไม่ควรมีไอดีซ้ำกันครับ
เพราะงั้นผมจึงย้ายโค้ดตรง
Code (PHP)
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat");
$("#stat").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id").val() + "&status=" + $("#status").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
เข้าไปข้างในลูป while ด้วย แล้วก็เพิ่ม $i เข้าไปเพื่อให้มันมองเป็นคนล่ะตัวกัน
|
|
|
|
|
Date :
2014-05-27 17:08:36 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันที่จริงคุณควรจะเขียนโค้ดตรง
Code (PHP)
<script type="text/javascript">
$(document).ready(function()
{
$("#submit").click(function()
{
//var id = $("#id").val();
//var status = $("#status").val();
//var txt=$('#form1').serialize();
var msgbox = $("#stat");
$("#stat").html('<img src="img/ajax-load.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "GET",
url: "update_work.php",
data: "id=" + $("#id").val() + "&status=" + $("#status").val(),
success: function(msg){
if(msg == 'OK')
{
$("#submit").html('<img src="img/ico_bifag.png" align="absmiddle">');
//msgbox.html('<img src="img/ico_bifag.png" align="absmiddle">');
}
else
{
$("#submit").html('<img src="img/no.png" align="absmiddle">');
//msgbox.html('<img src="img/no.png" align="absmiddle">');
}
}
});
});
});
</script>
ให้เป็น function ข้างนอกลูป while แล้วค่อยเรียกใช้งานเมื่อตอนเกิด event click ที่ submit แทนครับ จะได้ไม่เกิดโค้ดเดียวกันซ้ำ ๆ
|
|
|
|
|
Date :
2014-05-27 17:12:17 |
By :
WiTT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|