可能重複:
Passing multiple parameter to PHP from Javascript從Javascript傳遞數據到PHP
目前我正在試圖從JavaScript數據傳遞到PHP。我已經從Javascript訪問PHP腳本,除了沒有信息存儲在$_Post
變量中。我甚至試過$_Get
和$_Request
以確保它不存儲在那裏。不是。有人可以幫幫我嗎?我正在使用的功能如下。變量str是我在javascript中創建的一些東西,我覺得它好像看不到有用的東西。他們不是從HTML表單獲得的。 PHP腳本也在下面。
謝謝
Javascript功能,應該是做信息傳遞。
function postForm(str) {
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e)
{
alert("ERROR: CAN NOT POST DATA");
}
}
}
try
{
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
xmlHttp.open("POST","BigInt2.php",true);
postStr = "msg="+escape(str);
alert("SENDING: "+postStr);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(postStr);
} catch(e)
{
alert("ERROR POSTING DATA");
}
}
PHP函數應該做信息打印作爲信息存儲在$ _Post全局變量中的概念證明。 BigInt2.php
<?php
echo$_Post['msg'];
echo$_Get['msg'];
echo$_Request['msg'];
?>
要不是有你不想具體原因..使用jQuery。它使這件事變得如此簡單。 – jli 2012-04-14 16:09:09
它的POST和GET ..不發佈和獲取 – Vamsi 2012-04-14 16:11:53