|
|
|
ทำไมมันโพสต์ Form ไม่ไปครับ ผมใช้ jQuery ในการส่งค่า |
|
|
|
|
|
|
|
บรรทัด success: alert('789'), ทำงานครับ แต่ test.php ไม่ทำงาน
Code (PHP)
<form class="form-horizontal" name="frm-contact" id="frm-contact" method="post">
<label>Your name : <input type="text" class="input-xlarge" name="txt-name" id="txt-name"></label>
<label>E-mail address : <input type="email" class="input-xlarge" name="txt-email" id="txt-email" placeholder="ex. [email protected]"></label>
<label>Subject : <input type="text" class="input-xlarge" name="txt-subject" id="txt-subject"></label>
<label>Description : <textarea class="input-xlarge" name="txt-description" id="txt-description"></textarea></label>
<br/><center>
<span class="btn btn-primary" id="sub-contact" onclick="return subContact()"><i class="icon-ok icon-white"></i> Sent</span>
<span class="btn" onclick="resetForm(\'frm-contact\')"><i class="icon-remove icon-black"></i> Cancel</span></center>
</form>
Code (JavaScript)
function subContact(){
$('#frm-alert').remove();
name = $('#txt-name').val();
email = $('#txt-email').val();
subject = $('#txt-subject').val();
description = $('#txt-description').val();
if(name=='' || email=='' || subject=='' || description==''){
$('<div class="alert alert-error" id="frm-alert"><a class="close" data-dismiss="alert" href="#">×</a>Please try again!</div>').appendTo('#contact-form');
$("#frm-alert").fadeIn(0).delay(1000).fadeOut(300);
return false;
}else{
if(IsEmail(email)){
$.post("test.php",{txtName:name,txtEmai:email,txtSubject:subject,txtDescription:description}); // 1
$.ajax({ // 2
type: 'POST',
url: 'test.php',
data: {name:'123'},
success: alert('789'),
dataType: dataType
});
//$.post("test.php",{name:'ss'});
return true;
}else{
$('<div class="alert alert-error" id="frm-alert"><a class="close" data-dismiss="alert" href="#">×</a>E-mail invalid!</div>').appendTo('#contact-form');
$("#frm-alert").fadeIn(0).delay(1000).fadeOut(300);
return false;
}
}
}
test.php
<script>
alert("ok");
</script>
Tag : PHP
|
ประวัติการแก้ไข 2012-06-09 13:16:19
|
|
|
|
|
Date :
2012-06-09 13:15:01 |
By :
t-monroe |
View :
1137 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ท่าจะให้แน่ใจจริงๆ ล่ะก็ ให้ส่งค่ากลับมากจาก test.php ดีกว่ามั้งครับ
Code (PHP)
<input type="text" id="fname" />
<button id="submitForm">Save Form</button>
<div id="callBack"></div>
<script>
$("button#submitForm").click(function(){
$.post("test.php" ,{ firstname:$("input#fname").val() } ,function(returnData){
$("div#callBack").html(returnData).css("color","red");
});
});
</script>
test.php
if(isset($_POST["firstname"]){
$sql = "insert / update ....";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows())
echo "Insert/Update successfully";
else echo "Actions failed";
}
|
|
|
|
|
Date :
2012-06-15 21:22:21 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|