|
 |
|
ถามเรื่อง innerHtmlหน่อยครับ คือว่าส่งค่าไปแล้วมันreponseกลับมาเป็นไม่มีค่าที่ส่งไป |
|
 |
|
|
 |
 |
|
คือว่าผม ส่งค่าผ่านjavascript ไปยังอีกไฟล์หนึ่งแล้วให้มันลอง echo ค่านั้นกลับมา ปรากฎว่ามันไม่มีค่าเลย ไม่รู้ว่าเป็นเพราะอะไร
Code (PHP)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<script>
// JavaScript Document
var req=false;
function showdata(tb)
{
alert(tb);//ทดสอบว่ามีค่ามาไหม
if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
req = new XMLHttpRequest();
if (req.overrideMimeType)
{
req.overrideMimeType('text/html');
}
} else if (window.ActiveXObject)
{ // IE
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e)
{
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!req)
{
alert('Cannot create XMLHTTP instance');
return false;
}
req.onreadystatechange=function()
{
if(req.readyState==3)
{
document.getElementById("download").innerHTML="Please waiting....";
}
if(req.readyState==4)
{
alert(req.responseText);
document.getElementById("download").innerHTML=req.responseText;
}
}
var url="showdata.php";
var str = Math.random();
var strsend="asd="+str;
strsend+="&tb="+tb;
alert(strsend);
req.open('POST',url,true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", strsend.length);
req.setRequestHeader("Connection", "close");
req.send(strsend);
}
</script>
</head>
<body>
<table bgcolor="#EEEEEE" align="center" width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<div id="Main">
<div id="main_left">
<table width="150" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="12" style="background:url(image/images/mydata_19.gif); width:12px; height:25px;"> </td>
<td align="center"style="background-image:url(image/images/mydata_20.gif); background-repeat:repeat-x; color:#FFF; font-family:Tahoma, Geneva, sans-serif; font-size:14px; font-weight:bold">Example</td>
<td width="13" style="background-image:url(image/images/mydata_21.gif); width:13px; height:25px;"> </td>
</tr>
<tr>
<td width="12"> </td>
<td>
<?
include('connect.php');
$sql="select*from exam ";
$result=mysql_query($sql);
echo"<ul>";
while($arr=mysql_fetch_array($result)){
$name=$arr['ex'];
echo "<li><a href='' id='$name' onclick='showdata(this.id);'>".$arr['ex']."</a></li>";
}
echo "</ul>";
?>
<br /></td>
<td width="13"> </td>
</tr>
</table>
</div>
<div id="main_rigth">
<div id="download">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16" style="background-image:url(image/images/mydata_23.gif); width:16px; height:25px"> </td>
<td align="center" style="background-image:url(image/images/mydata_24.gif);;height:25px; color:#FFF; font-size:14px; font-weight:bold; font-family:Tahoma, Geneva, sans-serif;">ข้อมูล</td>
<td width="15" style="background-image:url(image/images/mydata_25.gif); width:15px; height:25px"> </td>
</tr>
<tr>
<td> </td>
<? include('weblink.php');?>
<td> </td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
อันนี้หน้าที่รับค่าแล้วecho ค่ากลับมาครับ
Code (PHP)
<?php
include('connect.php');
$tb=$_POST["tb"];
echo $tb;
?>
Tag : PHP, Ajax

|
|
 |
 |
 |
 |
Date :
2010-08-18 15:01:23 |
By :
sagi |
View :
1189 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง alert ค่า tb ในfunction showdata() ดูก่อนครับ ถ้ามันไม่มีค่า ก็แสดงว่าเป็นตั้งแต่ $name' ที่ส่งไป showdata(this.id) แล้วมังครับ
|
 |
 |
 |
 |
Date :
2010-08-18 15:48:38 |
By :
arthiter2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีค่าครับ alert ดูแล้ว
|
 |
 |
 |
 |
Date :
2010-08-18 16:58:31 |
By :
sagi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
alert(strsend);
มีค่าหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2010-08-18 17:08:44 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนแรกผมก็คิดว่ามันไม่มีค่าเลยลองalert(strsend);ดูมันก็มีค่าครับ

|
ประวัติการแก้ไข 2010-08-18 18:33:38
 |
 |
 |
 |
Date :
2010-08-18 18:30:47 |
By :
sagi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งงครับ ไม่รู้มันเป็นเพราะอะไร แก้ไม่หายลอง ส่งตรงๆก็ไม่ได้
ผมลอง var tb="1234"; ก็ไม่ได้
|
 |
 |
 |
 |
Date :
2010-08-19 07:56:09 |
By :
sagi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|