<INPUT name=text class="inp" id="text" size=15 maxLength=40>
<INPUT name=text1 type=text1 class="inp" id="text1">获取text和text1两个表单的数据,然后发送到PHP接收,代码怎么写,求好心人,求版主javascriptjsphp数据
<INPUT name=text1 type=text1 class="inp" id="text1">获取text和text1两个表单的数据,然后发送到PHP接收,代码怎么写,求好心人,求版主javascriptjsphp数据
或者使用js先获取text和text1的内容,然后通过ajax发送到php去。
或者 ajax
<script>
function check(form) {
$.ajax({ type: 'POST', data: $(form).serialize(), url: 'xxx.php', dataType: 'html', complete: function (xhr) {
if (xhr.responseText == '1') alert('OK');
else alert(xhr.responseText);
}
});
}
</script>
</head>
<body>
<form onsubmit="return check(this)">
<INPUT name=text class="inp" id="text" size=15 maxLength=40>
<INPUT name=text1 type=text1 class="inp" id="text1">
<input type="submit" value="submit" />
</form>
</body>
</html>
xxx.php
$text=$_POST["text"];
$text1=$_POST["text1"];
//...其他代码echo "1";
die();
<script>
function check(form) {
$.ajax({ type: 'POST', data: $(form).serialize()+'&url='+encodeURIComponent(location.href), url: 'xxx.php', dataType: 'html', complete: function (xhr) {
if (xhr.responseText == '1') alert('OK');
else alert(xhr.responseText);
}
});
}
</script>
</head>
<body>
<form onsubmit="return check(this)">
<INPUT name=text class="inp" id="text" size=15 maxLength=40>
<INPUT name=text1 type=text1 class="inp" id="text1">
<input type="submit" value="submit" />
</form>
</body>
</html>
<INPUT name=text1 type=text1 class="inp" id="text1">什么东西。不伦不类的。
if(isset($_POST['text'])&&isset($_POST['text1']))
{
$string = "text:".$_POST['text']." text1:".$_POST['text1']."\r\n";
$file = fopen("1.txt", "a");
fwrite($file, $string);
fclose($file);
}
?>
我的PHP是这样写的,这样只能接收到text和text1的数据保存1.txt文件里,location.href怎么接收?
if(isset($_POST['text'])&&isset($_POST['text1']))
{
$string = "text:".$_POST['text']." text1:".$_POST['text1']." URL:".$_POST['URL']."\r\n";
$file = fopen("1.txt", "a");
fwrite($file, $string);
fclose($file);
}
?>
php的$_POST获取键值区分大小写的??URL改成url就行了,发送的数据键名称是小写的$string = "text:".$_POST['text']." text1:".$_POST['text1']." URL:".$_POST['url']."\r\n";
http://localhost/aa.htm?text=123&text1=123
提交后URL变成这样,我想不要出现"?text=123&text1=123“
就http://localhost/aa.htm行了