  | 
              
	              
	                
  
    
	 
        การประยุกต์ scan qrcode ผ่าน webcam โดยใช้ jsQR Library เพิ่มสคริป อย่างไรให้สามารถ Submit ได้ทันทีที่ Scan     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                สอบถาม จากสคริปนี้ ต้องการ ให้ทันที ที่ สแกน QR Code แล้ว ให้ submit เลยครับ ต้อง ไปดึงข้อมูลผ่าน ajax อย่างไรครับ  
https://www.ninenik.com/%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%A2%E0%B8%B8%E0%B8%81%E0%B8%95%E0%B9%8C_scan_qrcode_%E0%B8%9C%E0%B9%88%E0%B8%B2%E0%B8%99_webcam_%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89_jsQR_Library-981.html 
 
Code 
var video = document.createElement("video"); 
    var canvasElement = document.getElementById("canvas"); 
    var canvas = canvasElement.getContext("2d"); 
    var loadingMessage = document.getElementById("loadingMessage"); 
    var outputContainer = document.getElementById("output"); 
    var outputMessage = document.getElementById("outputMessage"); 
    var outputData = document.getElementById("outputData"); 
	var beepsound = document.getElementById("beepsound"); 
	var outputQrcode = document.getElementById('outputqrcode'); 
	var TLR,TRR,BRL,BLL; 
	var code; 
	var waiting; 
     
	   
	   
    function drawLine(begin, end, color) { 
      canvas.beginPath(); 
      canvas.moveTo(begin.x, begin.y); 
      canvas.lineTo(end.x, end.y); 
      canvas.lineWidth = 4; 
      canvas.strokeStyle = color; 
      canvas.stroke(); 
	 
	  return true; 
    } 
 
    // Use facingMode: environment to attemt to get the front camera on phones 
    navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function(stream) { 
      video.srcObject = stream; 
      video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen 
      video.play(); 
      requestAnimationFrame(tick); 
    }); 
 
    function tick() { 
      loadingMessage.innerText = "⌛ Loading video..." 
      if (video.readyState === video.HAVE_ENOUGH_DATA) { 
        loadingMessage.hidden = true; 
        canvasElement.hidden = false; 
        outputContainer.hidden = false; 
 
        canvasElement.height = video.videoHeight; 
        canvasElement.width = video.videoWidth; 
		canvas.drawImage(video, 0, 0, canvasElement.width, canvasElement.height); 
		if(!video.paused){				 
			var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height); 
			 code = jsQR(imageData.data, imageData.width, imageData.height, { 
			  inversionAttempts: "dontInvert", 
			});					 
		} 
        if (code) { 
          TLR = drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58"); 
          TRR = drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58"); 
          BRL = drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58"); 
          BLL = drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58"); 
          outputMessage.hidden = true; 
          outputData.parentElement.hidden = false; 
          outputData.innerText = code.data; 
		  if(code.data!="" && !waiting && TLR==true && TRR==true && BRL==true && BLL==true ){ 
		  	console.log(code.data); 
			// สามารถส่งค่า code.data ไปทำงานอย่างอื่นๆ ผ่าน ajax ได้ 
		  	video.pause(); 
			beepsound.play(); 
			beepsound.onended = function() { 
				beepsound.muted = true; 
			}; 
			  // ใช้ jquery เรียกใช้งาน ajax ใช้ code.data เป็น id ของข้อมูลที่เราจะอัพเดท 
        $.post("update.php",{ 
            id:code.data 
        },function(res){ 
            console.log("update completed"); 
        }); 
			   
			   
			   
			// ให้เริ่มเล่นวิดีโอก่อนล็กน้อย เพื่อล้างค่ารูป qrcod ล่าสุด เป็นการใช้รูปจากกล้องแทน 
			setTimeout(function(){ 
				video.play(); 
			},4500); 
			// ให้รอ 10 วินาทีสำหรับการ สแกนในครั้งจ่อไป 
			 waiting = setTimeout(function(){ 
			 	TLR,TRR,BRL,BLL = null; 
				beepsound.muted = false; 
				if(waiting){ 
					clearTimeout(waiting); 
					waiting = null;					 
				} 
			  },10000);					 
		  } 
        } else { 
          outputMessage.hidden = false; 
          outputData.parentElement.hidden = true; 
        } 
      } 
      requestAnimationFrame(tick); 
    } 
 
 
  Tag : PHP               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2020-12-01 01:01:43 2020-12-01 01:03:19 2020-12-01 01:05:15 2020-12-01 01:06:22 2020-12-01 01:07:42 2020-12-01 01:08:33 2020-12-01 11:30:45 2020-12-01 12:50:25	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2020-12-01 01:00:19 | 
                      By :
                          ruti | 
                      View :
                          3060 | 
                      Reply :
                          5 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ได้แล้วครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2020-12-03 17:38:08 | 
                        By :
                            ruti | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 แล้วไฟล์ update.php ที่จะรับข้อมูลเข้า ทำอย่างไรครับ 
 
(ผมกำลังหาโค้ดอ่าน qrcode แล้วส่งข้อมูลไป ดึงข้อมูลในฐานข้อมูลมาอัพเดต ผมยัง งงๆ อยู่ครับผม ... ไฟล์ข้างต้นอ่านได้แล้ว แต่เวลาจะส่งไปและรับทาง update.php นี่ยังไม่เข้าใจครับ ... ) พอจะมีตัวอย่างบ้างไหมครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2021-01-20 20:51:00 | 
                        By :
                            หนุ่ม | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
      		  
	
     | 
   
 
                 |