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到數組就可以了。