|
 |
|
รบกวนท่านผู้รู้ ช่วยเหลือกระผมในเรื่องของ JQuery+PHP สักนิดครับผม รบกวนอ่านด้านในสักหน่อยนะครับ ขอบคุณอย่างสูง |
|
 |
|
|
 |
 |
|
หน้าฟอร์มรับข้อมูล
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<div id="result"></div>
Teacher Name<input type="text" name="tname" id="tname" /><br />
Surname<input type="text" name="tsname" id="tsname" /><br />
<input type="button" value="Save Data" id="submitForm" />
<script>
$("#submitForm").click(function(){
var message = "";
var colorText;
if($("#tname").val().length < 5 ){
alert('ชื่ออย่างน้อย 5 ตัวอักษร!');
$("#tname").focus();
}else
if($("#tsname").val().length < 5 ){
alert('นามสกุลอย่างน้อย 5 ตัวอักษร!');
$("#tsname").focus();
}else{
$.post("teacher_save.php",{tname:$("#tname").val() , tsname:$("#tsname").val()},function(backingData){
if(backingData == "success"){
message = "บันทึกข้อมูลสำเร็จแล้วครับ";
colorText = "green";
}else{
message = "การบันทึกข้อมูลล้มเหลว";
colorText = "red";
}
$("div#result").html(message).css("color",colorText);
});
}
});
</script>
ไฟล์ teacher_save.php
if(isset($_POST["tname"] , $_POST["tsname"]))
{
$Tname=$_POST["tname"];
$Tsname=$_POST["tsname"];
mysql_query("INSERT INTO teacher(TID,Tname,Tsname,Ttel,Troom) values('$TID','$Tname','$Tsname','$Ttel','$Troom')") or die(mysql_error());
echo "success";
}
?>
ทดลองดูน่ะครับ น่าจะประมาณนี้แหล่ะ
ไปเพิ่มตัวแปร $Ttel , $Troom เอาเองน่ะครับ
|
 |
 |
 |
 |
Date :
2012-11-29 11:16:16 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
: ตอบความคิดเห็นที่ : 1 เขียนโดย : sakuraei เมื่อวันที่ 2012-11-29 11:16:16
รายละเอียดของการตอบ ::
จากการสังเกตโค๊ดนี้
แปลได้ความว่า
สร้างตัวแปร มา สองตัว
แล้วเช็คค่าในช่อง กรอก 1 หากไม่น้อยกว่า 5
จะไปตรวจสอบที่ tsname
หากไม่น้อยกว่า 5
ก็ไปที่หน้า php
แล้วกลับมาแสดงผลที่หน้าเดิม
ประมาณนี้ใช่ไหมครับ
ตรงสเป็คผมเลย
เพียงแต่ส่งที่ผมไม่รู้ว่ามันคืออะไร
อาจจะเป้นการอ่านน้อยของผมด้วยแหละครับ
เช่น .val คือค่า
.click คือ คลิกเม้า
.focus คือตรวจสอบ
.html คืออะไร ?
.css คืออะไร ?
ผมคงต้องศึกษาอีกเยอะเลยแหละครับ
ว่า Jquery หรือ Ajax มันมี .อะไรบ้าง ทำงานยังไง
สงสัยผมกลับไปทำแบบเดิม น่าจะเข้าใจง่ายกว่านะครับ
T_T
คิดแล้วท้อ
แต่ยังไงก็ขอบคุณนะครับ ^ ^
|
 |
 |
 |
 |
Date :
2012-11-29 11:40:50 |
By :
INTz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ค่อยๆอ่านบทความไปทีละบทแล้วทำตามโค้ด เพื่อเรียนรู้ไปทีละขั้น
หรือถ้าจะให้ง่ายก็ไปหาหนังสือภาษาไทยมาอ่านจะดีกว่าครับ
จริงๆแล้ว jquery ไม่ได้ยากเลยครับ ถ้าเป็นเมื่อไหร่ก็จะเขียน web apps ได้ง่ายขึ้นเยอะ
แนะนำให้เริ่มหัด jquery ทันทีครับ
|
 |
 |
 |
 |
Date :
2012-11-29 11:55:55 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|