|
|
|
PHP CI + Jquery ช่วยด้วย !! ทำยังไงก็หาไม่เจอ ไม่รู้ว่าผิดตรงไหน ทำให้เรียกใช้ post ใน jquery ไม่ได้ค่ะ |
|
|
|
|
|
|
|
ช่วยด้วยค่ะ หามานานจังแล้ว หาไม่เจอจริงๆว่าเพราะอะไร ถึงเรียกใช้ post ไม่ได้
code หน้า template
Code (PHP)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="assets/css/Adminstyle.css"></link>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<title>OnlineShop---AdminPage</title>
<script type="text/javascript">
$( document ).ready(function() {
alert('start');
$(function() {
$('.Topmain').click(function(){
var refID = $(this).data("ref");
$('.topSub_'+refID).toggle();
});
});
});
function EditVal(ID) {
$("input.editbox_"+ID).show();
$("a.Update_"+ID).show();
$("a.Cancel_"+ID).show();
$("a.Edit_"+ID).hide();
$("#span_"+ID).hide();
}
function CancelVal(ID) {
$("input.editbox_"+ID).hide();
$("a.Update_"+ID).hide();
$("a.Cancel_"+ID).hide();
$("a.Edit_"+ID).show();
$("#span_"+ID).show();
}
function UpdateVal(ID,obj) {
var txtVal = obj.closest("tr").find("input[type=text]").val();
$.post("shop_TopicController/EditVal",
{
TopName: txtVal,
TopID : ID
},
function(data, status){
alert('แก้ไขข้อมูลสำเร็จ');
$("input.editbox_"+ID).hide();
$("a.Update_"+ID).hide();
$("a.Cancel_"+ID).hide();
$("a.Edit_"+ID).show();
$("#span_"+ID).show();
$("#span_"+ID).html(txtVal);
});
}
function AddMainVal() {
var txtVal = $("#txtMain").val();
// alert(txtVal);
$.post("shop_TopicController/AddTopMain",
{
TopName: txtVal
},
function(data, status){
alert('เพิ่มข้อมูลแล้ว');
$('.MainAdd').hide();
});
}
function AddSubVal(ID) {
// alert('test');
var txtVal = $("#txtSub_"+ID+"").val();
//alert(ID);
//alert(txtVal);
$.post("shop_TopicController/AddTopSub",
{
TopName: txtVal,
TopID : ID
},
function(status){
alert(status);
alert('เพิ่มข้อมูลแล้ว');
$('.topSub').show();
$('.MainAdd').hide();
});
}
function DeleteVal(ID) {
$.post("shop_TopicController/Delete",
{
TopID : ID
},
function(data, status){
alert('ลบข้อมูลแล้ว')
$('.topSub').show();
$('.MainAdd').hide();
});
}
</script>
</head>
<body>
<div id="Header">
<h1>Hello My templates</h1>
</div>
<div id="Navigation">
<ol>
<li><a href="#">first</a></li>
<li><a href="#">second</a></li>
<div id="Panel1">
<li><a href="#">third</a></li>
<ol>
<br><li>first</li></br>
<br><li>second</li></br>
<br><li>third</li></br>
</ol>
</div>
</ol>
</div>
<div id="Content">
<div id="right-side">
<h2>เนื้อหา</h2>
<!-- <iframe id="iframe_target" width="1000" height="1000" frameborder="0" name="iframe_target" src="#"></iframe>-->
</div>
<div id="left-side">
<br><br>
<table class="simply" >
<tr bgcolor="#EBEBD8" >
<th>Topic</th>
<th></th>
<th></th>
<th onclick="$('#MainAdd').toggle();">เพิ่ม</td>
</tr>
<tbody>
<!-- AddMain -->
[color=black]<tr id ="MainAdd" class="MainAdd" bgcolor="#EBEBD8" style="display:none;">
<td ><input type="text" size="15" id="txtMain" class="txtMain" Name="txtMain"/></td>
<td></td>
<td></td>
<td><a href='#' class="AddMain" onclick="AddMainVal()">Add</a></td>
</tr>
<!-- AddMain -->
<?php
$i = 0;
foreach($rs as $row){
$i++;
?>
<tr class="Topmain" bgcolor="#CCCC99" data-ref="<?php echo $row['TopID'];?>">
<td height="20" align="center" width="200" bgcolor="#EBEBD8" >
<span class="text" id="span_<?php echo $row['TopID'];?>"><?php echo $row['TopName']; ?></span>
<input type="text" id="txtVal" Name="txtVal" value="<?php echo $row['TopName']; ?>" style="display:none;" class="editbox_<?php echo $row['TopID'];?>"/>
</td>
<td height="10" onclick="$('#SubAdd_<?php echo $row['TopID'];?>').toggle();">เพิ่ม</td>
<td height="10" >
<a href='#' class="Edit_<?php echo $row['TopID'];?>" onclick="EditVal('<?php echo $row['TopID'];?>');" >Edit</a>
<a href='#' style="display:none;" class="Update_<?php echo $row['TopID'];?>" onclick="UpdateVal('<?php echo $row['TopID'];?>',$(this));">Update</a>
<a href='#' style="display:none;" class="Cancel_<?php echo $row['TopID'];?>" onclick="CancelVal('<?php echo $row['TopID'];?>');">Cancel</a>
</td>
<td height="10" bgcolor="#FF99CC" >
<a href='#' class="Delete" onclick="DeleteVal('<?php echo $row['TopID'];?>',$(this));">ลบ</a>
</td>
</tr>
<!----- AddSub -->
<tr id ="SubAdd_<?php echo $row['TopID'];?>" bgcolor="#CCCC99" style="display:none;">
<td ><input type="text" size="15" id="txtSub_<?php echo $row['TopID'];?>" Name="txtSub_<?php echo $row['TopID'];?>"/>
</td>
<td></td>
<td></td>
<td>
<a href='#' class="Add" onclick="AddSubVal('<?php echo $row['TopID']; ?>')" >เพิ่ม</a
</td>
</tr>
<!--- AddSub -->
<?php
$sql = "Select*from shop_topic where TopPP =".$row['TopID']." ";
$rd = $this->db->query($sql);
foreach($rd->result_array() as $rowPP)
{
?>
<tr bgcolor="#CCCC99" class="topSub_<?php echo $row['TopID'];?>" style="display:none;" >
<td height="20" align="center" width="200" bgcolor="#EBEBD8" style="cursor:pointer;" >
<span class="text" id="span_<?php echo $rowPP['TopID'];?>"><?php echo $rowPP['TopName']; ?></span>
<input type="text" id="txtVal" Name="txtVal" value="<?php echo $rowPP['TopName']; ?>" style="display:none;" class="editbox_<?php echo $rowPP['TopID'];?>" name="one_input_<?php echo $rowPP['TopName'];?>"/>
</td>
<td height="10" bgcolor="#FF99CC" onclick="$('#EditSub_<?php echo $rowPP['TopID'];?>').toggle();" >
<a href='#' class="Edit_<?php echo $rowPP['TopID'];?>" onclick="EditVal('<?php echo $rowPP['TopID'];?>');" >Edit</a>
<a href='#' style="display:none;" class="Update_<?php echo $rowPP['TopID'];?>" onclick="UpdateVal('<?php echo $rowPP['TopID'];?>'">Update</a>
<a href='#' style="display:none;" class="Cancel_<?php echo $rowPP['TopID'];?>" onclick="CancelVal('<?php echo $rowPP['TopID'];?>');">Cancel</a>
</td>
<td height="10" bgcolor="#FF99CC" ><a href='#' class="Delete" onclick="DeleteVal('<?php echo $rowPP['TopID'];?>',$(this));">ลบ</a> </td>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
<table>
</div>
</div>
<div id="Footer">
<h1>Footer</h1>
</div>
</body>
</html>
และในไฟล์ controller
Code (PHP)
<?php
class shop_TopicController extends CI_Controller {
public function index() {
$rs = $this->db->query('select * from shop_topic where TopPP = "0"');
$data['rs'] = $rs->result_array();
$this->load->view('shop_topic',$data);
}
public function AddTopSub() {
$topID = $this->findMax();
$data=array(
"TopID"=>$this->findMax(),
"TopName"=>$this->input->post('TopName'),
"TopPP"=>$this->input->post('TopID'),
);
$this->db->insert('shop_topic',$data);
$this->showInsert($topID);
}
public function EditVal() {
$data = array(
"TopName"=>$this->input->post('TopName'),
);
$this->db->where('TopID', $this->input->post('TopID'));
$this->db->update('shop_topic', $data);
$this->load->view('shop_topic');
}
public function Delete() {
$this->db->delete('shop_topic', array('TopID' => $this->input->post('TopID')));
}
public function AddTopMain(){
$topID = $this->findMax();
$data=array(
"TopID"=>$this->findMax(),
"TopName"=>$this->input->Post('TopName'),
"TopPP"=> '0',
);
$this->db->insert('shop_topic',$data);
}
public function showInsert($para) {
$rs = $this->db->get_where('shop_topic', array('TopID' => $para));
$data['rs'] = $rs->result_array();
$this->load->view('shop_topic',$data);
}
public function findMax() {
$Max = "SELECT Substring((10000 + Max(TopID)+ 1),2,6) AS MX FROM shop_topic";
$query = $this->db->query($Max);
foreach($query->result() as $row){
$maxnumber = $row->MX;
}
return $maxnumber;
}
}
?>
และ อันนี้เป็นหน้าตาตัวอย่าง (ยังไม่เสร็จ)
ขอควากรุณาด้วยค่ะ จขกท ตาลายมาก @_@
Tag : PHP, jQuery, CodeIgniter Framework
|
|
|
|
|
|
Date :
2015-05-03 03:08:39 |
By :
Saw-Series |
View :
990 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อาจเยอะไป ไฟล์แรกดูตรง บรรทัก 153 - 160
กับ บรรทัด 184-194
|
|
|
|
|
Date :
2015-05-03 03:13:45 |
By :
Saw-Series |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่มีใครสามารถช่วยได้ แง๊ T^T
|
|
|
|
|
Date :
2015-05-03 12:28:13 |
By :
Saw-Series |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยด้วยค่าาาา T^T
|
|
|
|
|
Date :
2015-05-03 13:19:42 |
By :
Saw-Series |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$.post("<?php echo base_url(); ?>" + "shop_TopicController/AddTopMain",
อย่าลืมโหลด url helper ละ
|
ประวัติการแก้ไข 2015-05-03 19:10:08
|
|
|
|
Date :
2015-05-03 19:09:42 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|