A. 请问Ajax post的php怎么写
$_POST['email']
改为
$_POST['e']
因为你前端传过来的参数名是e,不是email
B. PHP+Ajax用POST方法提交的数据,PHP页面收不到
要设置form的提交方式,一般有两种方式get和post默认的是get
<form
name="form" method="post">
如果不填写method的话,默认将以get方式提交。
C. php+ajax表单post问题
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
这个是必须加的!否则就出错。
建议使用jquery,就不用写这些无用的代码了!
而且使用简单!
你找一个好一点的例子吧,仿写,我的空间有这种原始的!
D. 这个html加php的ajax的实例是GET方式的,要改成POST方式怎么改
前端改成post了,后端也要跟改。
E. ajax $.post 代码 php
比如是这样
<scripttype="text/javascript">
$().ready(function(){
$('#selectNum').change(function(){
varidValue=$(this).val();
//采用POST方式调用服务
$.post('a.php',{id:idValue},function(text,status){
//这里判断一下staus
alert(text);});
})
})
</script>
然后再 b.php 页面。就可以通过 $_POST 获取到ID的东西了。
处理完 通过,返回一个 staus 的状态值
F. php 怎么使用ajax,给个例子
实现ajax需要三个文件,一个是html的表单文件,一个是js的核心文件,一个是php的后台文件。
下面的是html文件,当键盘按下时触发showHint方法,在showHint方法中会有ajax的核心内容,实例化,获取地址,获取数据并展示等等。
复制代码 代码如下:
<html>
<head>
<script src="clienthint.js"></script>
</head>
<body>
<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
下面是js的内容clienthint.js。
复制代码 代码如下:
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML=""
return
}
//获取xmlHttpObject对象,如果为空,提示浏览器不支持ajax
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
//获取url
var url="gethint.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
//回调函数,执行动作
xmlHttp.onreadystatechange=stateChanged
//open
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
//将获取的信息插入到txtHint中
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
//获取xml对象
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
下面是php的内容。根据ajax对象传入的参数,获取相应的数据。
复制代码 代码如下:
<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Jiqing";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}
//Set output to "no suggestion" if no hint were found
//or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
G. php ajax post如何处理多个返回信息
$.post是提供简单的封装的ajax post请求的方法,没办法进行更详细的配置。改为使用$.ajax把,里面有一个参数可以配置超时时间如$.ajax({url:"xxx.php",type:"POST",dataType:"json",timeout:60000, //超时时间,现在设置为60s。success:function(data){ console.log(data);}});更详细的配置可以查看jQuery的API文档。另外需要你的服务器端配置的超时时间不能小于jQuery里面配置的。要不然jQuery还没有超时,服务器端直接返回timeout了。同时优化一下服务端的处理,提高相应速度也是一个不错的选择。
H. PHP AJAX 用POST方法发送数组
我没有查到,用jquery是可以的吧,但是用ajax有点困难,我是把数组join成string,然后到了寂寞端再解析一下string到数组就可以了。