|
 |
|
ปัญหา Jquery หา button ไม่เจอหลังจากส่งค่าไปอีก pageนึงเเล้วกลับมา page เดิม |
|
 |
|
|
 |
 |
|
แก้ตามโจทย์ที่ขอ แล้วกันนะ
ส่วนจะเอาไปใช้ยังไงก็ ดัดแปลงเองละ
Code (PHP)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" >
$(document).ready(function(){
$("#btn_ok").click(function(){
var name= $('#txt_name').val();
var pro= 'profile';
//alert(name);
$.ajax({
type: 'POST',
url: 'test1.php',
data: "txt_name="+name+"&pro="+pro,
success: function(data){ //alert(data);
data_new = data.split(String.fromCharCode(6));
$("#divPostData").html(data_new[0]+''+data_new[1]);
}
});
/*
$.post("test2.php", { val: "profile", name: $("#txt_name").val()}, function(data) {
$("#divPostData").html( '<input type="text" name="textbox1" id="textbox1" value="'+data.name+'" /><br/>
<input type="button" name="btn_pro" id="btn_pro" value="Enter" />');
},'json');
});
$('#btn_pro').click(function(){
alert("Enter OK");
*/
});
});
</script>
<!--
มีปัญหาเรื่อง เวลาส่งค่าไปอีก page เเล้วกลับมา page เดิม เเล้วได้สร้าง buttonมานึงอัน เวลากดมันเเล้วมันหาปุ่มนั้นไม่เจอครับ
มีวืธีแก้ไขยังไงเหรอครับ
code page1 ชื่อ test
-->
<div id="divPostData"></div>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="txt_name" id="txt_name" />
</label>
<label>
<input type="button" name="btn_ok" id="btn_ok" value="Button" />
</label>
</form>
test1.php
Code (PHP)
<?php
$val = $_POST[pro];
if ($val == 'profile')
{
$name = $_POST[txt_name];
//$name = 'aaa';
echo json_encode(array('name'=>$name)).'</br>';
echo chr(6).'<input type="text" name="textbox1" id="textbox1" value="'.$name.'" />
<input type="button" name="btn_pro" id="btn_pro" value="Enter" />';
}
?>
|
 |
 |
 |
 |
Date :
2011-12-09 11:55:48 |
By :
puchong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้ละครับ
test.php
Code (JavaScript)
<script type="text/javascript">
$(document).ready(function(){
$("#btn_ok").click(function(){
var name= $('#txt_name').val();
var pro= 'profile';
/* $.ajax({
type: 'POST',
url: 'test1.php',
data: "txt_name="+name+"&pro="+pro, success: function(data){
data_new = data.split(String.fromCharCode(6));
$("#divPostData").html(data_new[0]+''+data_new[1]);
$("#btn_pro").click(function(){
alert("Pro ok");
});
}
});*/
$.post("test1.php", { name: name, pro: pro}, function(data) {
$("#divPostData").html(data.btn);
$("#btn_pro").click(function(){
alert("Pro ok");
});
},'json');
});
});
</script>
Code (PHP)
<body>
<div id="divPostData"></div>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="txt_name" id="txt_name" />
</label>
<label>
<input type="button" name="btn_ok" id="btn_ok" value="Button" />
</label>
</form>
</body>
test1.php
Code (PHP)
$val = $_POST["pro"];
if ($val == 'profile')
{
$name = $_POST["name"];
$btn = '<input type="text" name="textbox1" id="textbox1" value="'.$name.'" /><input type="button" name="btn_pro" id="btn_pro" value="Enter" />';
echo json_encode(array('name'=>$name,'btn'=>$btn));
}
/*$val = $_POST[pro];
if ($val == 'profile')
{
$name = $_POST[txt_name];
echo json_encode(array('name'=>$name)).'</br>';
echo chr(6).'<input type="text" name="textbox1" id="textbox1" value="'.$name.'" />
<input type="button" name="btn_pro" id="btn_pro" value="Enter" />';
}*/
|
 |
 |
 |
 |
Date :
2011-12-12 10:10:20 |
By :
grandraftz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|