我有这样的场景:
-
在我的index.html
- 一个文本框的格式,并用POST方法和行动另一个名为页面middlescan.html
- middlescan.html按钮在body onload事件中调用一个名为checkpost的js函数
- 将js函数放入midlescan.html中,该函数必须检查$ _post变量是否设置为空或非空,如果是,则返回index.html
我的问题是: 如何在javascript中检查是否有$ _POST调用?
我现在的情况:
在我的index.html:
<form id="form1" name="form1" method="post" action="middlescan.html"> <p> <label for="oStxt"></label> </p> <table width="60%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6%"> </td> <td width="17%"><input type="text" name="oStxt" id="oStxt" /></td> <td width="77%"><input type="submit" name="button" id="button" value="Invia" /></td> </tr> </table> </form>
在middlescan.html
<body onload = ckpost()>
3.in JS文件
function ckpost() {
// only continue if we have a valid xmlHttp object
if (xmlHttp)
{
// try to connect to the server
try
{
// initiate reading the async.txt file from the serve
xmlHttp.open(“POST", "php/check.php", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
// change cursor to "busy" hourglass icon
}
// display the error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
}
}
}
在我checkpost.php
<?php $datat = array(); if(!is_null($_POST['oStxt']) || $_POST['oStxt'] != "") {
$ datat [urlpost] = $ _POST [ 'oStxt'];
} else {
$ datat [urlpost] =“nullo”;
}
//克里奥IL文件JSON 回声json_encode($ datat);
?>
,但反应是有史以来 “nullo” 有什么不对?
在此先感谢
只能通过AJAX。 JavaScript是***客户端***脚本。 '$ _POST'是PHP的一部分,它是***服务器端***脚本。 – War10ck