  | 
              
	              
	                
  
    
	 
        สอบถามหน่อยครับ ผมลองทำตามในเว็บแล้วมันไม่ได้ รบกวนช่วยดูให้หน่อยยครับ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                https://www.ninenik.com/forum_view_233_1.html 
https://www.ninenik.com/demo/simple_ajax_shop/simple_shop.php 
 
pp.php 
Code (PHP) 
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="js/jquery.js" type="text/javascript"></script>
    </head>
    <body>
        <?php
        session_start();
        header("Content-type:text/html; charset=UTF-8");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);
        ?>
        <?php
        if (count($_POST) > 0) {
            $_SESSION['ses_proname'][time()] = $_POST['pro_name'];
            $_SESSION['ses_qty'][time()] = $_POST['pro_qty'];
        }
        if ($_GET['clear']) {
            unset($_SESSION['ses_proname']);
            unset($_SESSION['ses_qty']);
            session_destroy();
            echo $_GET['clear']."55";
        }
        ?>
        <?php if (isset($_GET['showDtata'])) { ?>
            <table width="300" border="1" cellspacing="2" cellpadding="0">
                <tr>
                    <td align="center">#</td>
                    <td align="center">Pro</td>
                    <td align="center">Qty</td>
                </tr>
                <?php
                $i = 1;
                if (count($_SESSION['ses_proname']) > 0) {
                    foreach ($_SESSION['ses_proname'] as $key => $value) {
                        ?>  
                        <tr>
                            <td align="center"><?= $i ?></td>
                            <td align="left">   <?= $_SESSION['ses_proname'][$key] ?></td>
                            <td align="left">   <?= $_SESSION['ses_qty'][$key] ?></td>
                        </tr>
                        <?php
                        $i++;
                    }
                }
                ?>  
                <tr>
                    <td align="center"> </td>
                    <td align="center"> </td>
                    <td align="center"><input type="button" name="Clear" id="Clear" value="Clear"></td>
                </tr>
            </table>
        <?php } ?>
    </body>
</html>
 
 
getData.php 
Code (PHP) 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Simple Ajax Shop</title>
        <script src="js/jquery.js" type="text/javascript"></script>
    </head>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <table width="300" border="0" cellspacing="3" cellpadding="0">
                <tr>
                    <td width="50" align="center">Product</td>
                    <td width="121"><input type="text" name="pro_name" id="pro_name" /></td>
                </tr>
                <tr>
                    <td align="center">Qty</td>
                    <td><input type="text" name="pro_qty" id="pro_qty" /></td>
                </tr>
                <tr>
                    <td> </td>
                    <td><input type="button" name="addPro" id="addPro" value="Button" /></td>
                </tr>
            </table>
        </form>
        <br />
        <div id="showPro">
        </div>
        <script src="js/jquery/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $("#addPro").click(function () {
                    $.post("pp.php", $("#form1").serialize(), function () {
                        $("#showPro").load("pp.php?showDtata=1");
                        $("#form1")[0].reset();
                    });
                });
                $("#Clear").live('click', function () {
                    $.get("pp.php", {clear:1}, function () {
                        $("#showPro").load("pp.php?showDtata=1");
                    });
                });
            });
        </script>
    </body>
</html>
 
คือมันกดปุ่ม เคลียไม่ได้ แล้วถ้าต้องการลบในแถวนั้นๆทำยังไงครับ  
หรือมี ตย.ที่ดีกว่านี้ก็เสนอได้นะครับ ขอบคุณครับ
 
 
  Tag : PHP               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2017-09-30 16:27:32	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-09-30 16:23:56 | 
                      By :
                          PACKLpk | 
                      View :
                          975 | 
                      Reply :
                          13 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 session_start(); เอาไปไว้บันทัดแรก ของทั้งสองไฟล์ ถ้าขาดไฟล์ใดไฟล์หนึ่ง session หลุด 
 
Code (PHP) 
<?php session_start();?>
<!DOCTYPE html>
...
...
  
 
ส่วนคำสั่งนี้ 
header("Content-type:text/html; charset=UTF-8");  
บันทัดนี้ไม่ต้องใช้ มันคือ  
<!DOCTYPE html> 
<header> 
<meta charset="utf8"> 
 
2 บันทัดล่างนี้ 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
เปลี่ยนเป็น 
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/> 
<meta http-equiv="Pragma" content="no-cache"/> 
<meta http-equiv="Expires" content="0"/>                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-09-30 19:00:52 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   
 
มันขึ้นแบบนี้อะครับลองแก้แล้ว พอกดเคลียแล้วไม่เข้า 
Code (PHP) 
 if ($_GET['clear']) {
            unset($_SESSION['ses_proname']);
            unset($_SESSION['ses_qty']);
            session_destroy();
            echo $_GET['clear'] . "55";
        }
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-10-02 08:52:32 2017-10-02 08:52:38              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 08:44:12 | 
                        By :
                            PACKLpk | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 <input name="clear"> คุณไล่ตัวอักษรเล็กใหญ่ให้มันละเอียดสิครับ ของพวกนี้ต้องละเอียด                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 12:41:31 | 
                        By :
                            mr.v | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 หาไฟล์ jquery.js มาใส่หรือยัง??                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 14:21:14 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ที่ว่าเอามาใส่เนี่ยะ มีไฟล์ jquery.js ใน โฟลเดอร์ js แน่นะ 
ตย.จากที่มาไม่ผิด ใช้งานได้ปกติ 
เอา code ล่าสุด เต็มๆมาดูครับ 
 
ไม่งั้นไปทำตามตัวอย่างให้เป๊ะๆ เอาตาม ตย. ทุกบรรทัด แล้วเทียบกับของคุณ 
และอีกอย่างเลือกตัวอักษร เล็กใหญ่ ตั้งเป้น เล้กให้หมดครับ ชื่อไฟล์ ชื่อตัวแปร บลาๆ จะได้ไม่งงด้วย                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-10-02 15:57:06              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 15:53:39 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เปิดมาไฟล์ simple_shop.php ตำแหน่ง session_start(); ก็ผิดล่ะ     
ขอทดสอบอย่างอื่นก่อน                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 15:59:21 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   
ตามนั้นครับ 
 
เดี๋ยวมาสรุปให้ 
 
#สรุป 
1. ไฟล์ jquery ใน ตย.เป็น เวอร์เก่า คือ 1.4.2 ตอนนั้นน่าจะรับ event .live "click", อยู่ 
แต่ถ้าคุณใช้ version ใหม่ๆ ไม่น่าจะได้ 
2.ใน jquery ตัวใหม่ๆ ถ้า element สร้างหลังจาก jquery โหลดไปแล้ว จะไม่ใช้งาน element  นั้นได้  
ตรงนี้หมายถึง เมื่อคุณเปิดไฟล์ simple_shop.php ขึ้นมา ตัว jquery  ได้เรียกใช้งานไปแล้ว 
เมื่อคุณสร้างปุ่ม clear มาที่หลัง การทำงานของ การคลิก event .live "click" มันเลยไม่ทำงาน 
ฉนั้น ต้องเปลี่ยนไปใช้ click ตามปกติ 
 
simple_shop.php 
<!DOCTYPE html>
<?php
session_start();
?>
<html>
    <head>
        <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
        <script src="https://code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
        <title>Simple Ajax Shop</title>
    </head>
    <body>
        <form id = "form1" name = "form1" method = "post" action = "">
            <table width = "300" border = "1" cellspacing = "3" cellpadding = "0">
                <tr>
                    <td width = "50" align = "center">Product</td>
                    <td width = "121"><input type = "text" name = "pro_name" id = "pro_name" /></td>
                </tr>
                <tr>
                    <td align = "center">Qty</td>
                    <td><input type = "text" name = "pro_qty" id = "pro_qty" /></td>
                </tr>
                <tr>
                    <td> 
                    </td>
                    <td><input type = "button" name = "addPro" id = "addPro" value = "Button" /></td>
                </tr>
            </table>
        </form>
        <br />
        <div id = "showPro">
        </div>
        <script type="text/javascript">
            $(function () {
                $("#addPro").click(function () {
                    $.post("genPro.php", $("#form1").serialize(), function () {
                        $("#showPro").load("genPro.php?showDtata=1");
                        $("#form1")[0].reset();
                    });
                });
            });
        </script>
    </body>
</html>
 
 
genPro.php 
<?php
session_start();
if (count($_POST) > 0) {
    $_SESSION['ses_proname'][time()] = $_POST['pro_name'];
    $_SESSION['ses_qty'][time()] = $_POST['pro_qty'];
}
if (isset($_GET['clear'])) {
    unset($_SESSION['ses_proname']);
    unset($_SESSION['ses_qty']);
    session_destroy();
}
?>
<?php if (isset($_GET['showDtata'])) { ?>
    <table width="300" border="1" cellspacing="2" cellpadding="0">
        <tr>
            <td align="center">#</td>
            <td align="center">Pro</td>
            <td align="center">Qty</td>
        </tr>
        <?php
        $i = 1;
        if (count($_SESSION['ses_proname']) > 0) {
            foreach ($_SESSION['ses_proname'] as $key => $value) {
                ?>  
                <tr>
                    <td align="center"><?= $i ?></td>
                    <td align="left">   <?= $_SESSION['ses_proname'][$key] ?></td>
                    <td align="left">   <?= $_SESSION['ses_qty'][$key] ?></td>
                </tr>
                <?php
                $i++;
            }
        }
        ?>  
        <tr>
            <td align="center"> </td>
            <td align="center"> </td>
            <td align="center"><input type="button" name="clear" id="clear" value="clear"></td>
        </tr>
    </table>
    <script type="text/javascript">
        $(function () {
                        $("#clear").click(function () {
                    $.get("genPro.php", {clear: 1}, function () {
                        console.log(clear);
                        $("#showPro").load("genPro.php?showDtata=1");
                    });
                });
                           });
    </script>
<?php } ?>
 
 
สุดท้ายก็ยังมี Error 1 ตัว ลองไปหาทางแก้ดู เรื่องการตรวจสอบตัวแปร 
อ่านดูhttps://moremeng.in.th/2013/05/php-notice-undefined-index-notice-undefined-variable.html                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-10-02 16:13:47 2017-10-02 16:28:11              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-10-02 16:04:56 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
      		  
	
     | 
   
 
                 |