PDA

View Full Version : کجای این کد مشکل داره؟؟؟؟؟؟؟؟؟



zare_a87
جمعه 21 فروردین 1394, 18:35 عصر
صفحه اصلی


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
var pageurl="getName.php?param=";
var http=getHttp();

function Answer()
{
if(http.readystate==4)
{
r=http.responseText;
document.getElementById("tfname").value=r;
}
}

function Se()
{
var code=document.getElementById("tfcode").value;
alert(code);
http.open("GET",pageurl+code,true);
http.onreadystatechange=Answer;
http.send(null);

}


function getHttp()
{
var xmlhttp;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
if(typeof XMLHttpRequest !='Undefined')
{
xmlhttp=new XMLHttpRequest();
}
}
}
return xmlhttp;
}
</script>
</head>

<body>
<p>Code:
<label for="textfield"></label>
<input name="tfcode" type="text" onkeyup="" />
<input name="Button" type="button" onclick="Se();" value="Get City Name" />
</p>
<p>Name:
<label for="textfield"></label>
<input type="text" name="tfname" />
</p>
</body>
</html>


کد php



<?php
$c=$_GET["param"];
if ($c="1")
{
echo "کد انتخابی یک می باشد";
}
?>


برنامه طوریه که وقتی کد 1 وارد کد بدون رفرش شدن بایست پیام مطرح شده رو چاپ کنه
ولی این کار رو نمیکنه

کجای کد اشکال داره؟؟؟

Pedram77
جمعه 21 فروردین 1394, 21:24 عصر
این کد چرا اینقدر پیچیدس؟! این کد ساده تره کارم میکنه :

function ajaxLoad()
{
if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
else
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState==4 && xmlHttp.status==200)
{
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = xmlHttp.responseText;
}
}

xmlHttp.open("GET","script.php?tp="+tp,true);
xmlHttp.send();
}