嗨,我的ajax功能不起作用.......... [英] hi, my ajax function is not working ..........
问题描述
大家好,我是Ajax的新手,这是我在Ajax中的第一个程序。我不知道脚本中有什么问题。请帮我找出错误,主要错误是我想通过url传递的值。提前感谢你。
test.html
[HTML]<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN>
< HTML>
< HEAD>
< TITLE>新文件< / TITLE>
< META NAME =" Generator" CONTENT =" EditPlus">
< META NAME =" Author" CONTENT ="">
< META NAME =" Keywords" Keywords" CONTENT ="">
< META NAME =" Description" CONTENT ="">
< / HEAD>
< BODY>
< script language = " JavaScript的" type =" text / javascript">
函数ajaxFunction()
{
var ajaxRequest; //使Ajax成为可能的变量
尝试
{// opera + firefox safari
ajaxRequest = new XMLHttpRequest() ;
}
catch(e)
{
尝试
{
ajaxRequest = new ActiveXOhject(" Msxml2.XMLHTTP");
}
catch(e)
{
alert(你的浏览器不支持ajax);
返回false;
}
}
//创建一个接收服务器发送数据的函数
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
document.myform.name.value = ajaxRequest.responseText;
}
}
var empFirstName = document.getElementById(''empFirstName'')。value;
var queryString ="?empFirstName =" ; + empFirstName;
ajaxRequest .open(" GET"," test-ajax.php" + queryString,true);
ajaxRequest.send(null);
}
< / script>
< form name =" myform">
员工名字:< input type =" ;文本" id =" empFirstName">< / br>
< input type =" button"的onclick = QUOT; ajaxFunction()" value =" Test"
< / form>
< / BODY>
< / HTML>
[/ HTML]
我的php文件是
test-ajax.php
[PHP]<?php
$ error ="" ;;
include(" config.inc.php");
包括(connect.inc.php);
$ empFirstName = $ _GET [''empFirstName''];
$ sql =" SELECT * FROM userdetails wherer empFirstName =''$ empFirstName''" ;;
$ result = mysql_query($ sql)or die(mysql_error());
if($ result)
{
while($ row = mysql_fetch_array($ result))
{
echo" Employee Last Name:"。$ row [''empLastName''];
}
}
else
{
echo" Sorry" ;;
}
?> [/ PHP ]
hi everyone, i m very new to Ajax, and this is my first program in Ajax. I dont know what is wrong in the script. Please help me to find out the error, The main error is the value that i suppose to pass through url is not passing. thanking you in advance.
test.html
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script language="javascript" type="text/javascript">
function ajaxFunction()
{
var ajaxRequest; // the variable that makes Ajax possible
try
{ //opera + firefox safari
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
ajaxRequest = new ActiveXOhject("Msxml2.XMLHTTP");
}
catch (e)
{
alert("Your browser is not support ajax");
return false;
}
}
//create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState ==4)
{
document.myform.name.value = ajaxRequest.responseText;
}
}
var empFirstName = document.getElementById(''empFirstName'').value;
var queryString = "?empFirstName="+empFirstName;
ajaxRequest.open("GET","test-ajax.php"+queryString, true);
ajaxRequest.send(null);
}
</script>
<form name="myform">
Employee First Name:<input type="text" id="empFirstName"></br>
<input type="button" onclick="ajaxFunction()" value="Test">
</form>
</BODY>
</HTML>
[/HTML]
my php file is
test-ajax.php
[PHP]<?php
$error = "";
include ("config.inc.php");
include ("connect.inc.php");
$empFirstName = $_GET[''empFirstName''];
$sql = "SELECT * FROM userdetails wherer empFirstName=''$empFirstName''";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
while($row=mysql_fetch_array($result))
{
echo "Employee Last Name: ".$row[''empLastName''];
}
}
else
{
echo "Sorry";
}
?>[/PHP]
推荐答案
error ="" ;;
include(" config.inc.php");
include(" connect.inc.php");
error = "";
include ("config.inc.php");
include ("connect.inc.php");
empFirstName =
empFirstName =
_GET [''empFirstName''];
_GET[''empFirstName''];
这篇关于嗨,我的ajax功能不起作用..........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!