php ajax php ajax
<?phpheader("Content-Type:html/text;Charset=utf-8");$name = $_POST['name'];$email = $_POST['email'];$comment = $_POST['comment'];$fh = @fopen("14-6.txt","ab");fwrite($fh,"姓名:".$name,strlen($name));fwrite($fh,"email:".$email,strlen($email));fwrite($fh,"评论:".$comment,strlen($comment));fclose($fh);echo 1;?>
function $(id){ return document.getElementById(id);}function addcomment(){ var url = "14-6.php"; var status = document.getElementById("divmsg"); status.value="正在提交》》》"; var param = "name="+$("name").value+"email="+$("email").value+"comment="+$("comment").value; xmlhttp_request.onreadystatechange = function(){ if(xmlhttp_request.readyState==4 && xmlhttp_request.status == 200){//相应完全显示信息 alert (xmlhttp_request.responseText); if(xmlhttp_request.responseText == "1"){ status.value = "发表成功!!"; $("name").value=""; $("email").value=""; $("comment").value=""; }else{ status.value = "发表失败!请重新发表!"; } } } xmlhttp_request.open("POST",url,true); xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//设置头信息 xmlhttp_request.send(param);}
不知道为什么,这个responseText返回的是一大面的html代码.
回复讨论(解决方案)
上面就是alert(xmlhttp_request.responseText)返回的东西
你请求的是当前页面吗
那不是错误信息吗?
14-6.php 第 4 行的 $_POST['email'] 没有定义
var param = "name="+$("name").value+"email="+$("email").value+"comment="+$("comment").value;
应写作
var param = "name="+$("name").value+" &email="+$("email").value+" &comment="+$("comment").value;
我的是从一个html文件转到php文件的。
html代码在下面。我的一共才两个文件,一个html文件,一个php文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Insert title here</title><script type="text/javascript">var xmlhttp_request = false; //定义变量try{ if(window.ActiveXObject){ //判断浏览器是否是ActiveXObject对象 for(var i=5;i;i--){ //根据IE浏览器版本使用不同方法创建 try{ if(i==2){ xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP"); }else{ xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP."+i+".0"); xmlhttp_request.setRequestHeader("Content-Type","text/xml"); xmlhttp_request.setRequestHeader("Charset","utf-8"); } break; }catch(e){ xmlhttp_request = false; } } }else if(window.XMLHttpRequest){ //判断浏览器是否支持XMLHttpRequest对象 xmlhttp_request = new XMLHttpRequest(); if(xmlhttp_request.overrideMimeType){ xmlhttp_request.overrideMimeType('text/xml'); } }}catch(e){ xmlhttp_request = false;}function $(id){ return document.getElementById(id);}function addcomment(){ var url = "14-6.php"; var status = document.getElementById("divmsg"); status.value="正在提交...."; var param = "name="+$("name").value+"email="+$("email").value+"comment="+$("comment").value; xmlhttp_request.onreadystatechange = function(){ if(xmlhttp_request.readyState==4 && xmlhttp_request.status == 200){//相应完全显示信息 alert(xmlhttp_request.responseText); if(xmlhttp_request.responseText == "1"){ status.value = "发表成功!!"; $("name").value=""; $("email").value=""; $("comment").value=""; }else{ status.value = "发表失败!请重新发表!"; } } } xmlhttp_request.open("POST",url,true); xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//设置头信息 xmlhttp_request.send(param);}</script></head><body><form name="form" id="form" method="post" action=""> <p> </p> <p> </p> <p> </p> <p> </p> <table width="400" height="168" border="0" align="center" cellpadding="2" cellspacing="0"> <caption>发表评论</caption> <tr> <td >用户名:</td> <td align="center"> <lable> <input type="text" name="name" id="name" size="30" maxlength="20"/> </lable> </td> </tr> <tr> <td >email:</td> <td align="center"> <lable> <input type="text" name="email" id="email" size="30" maxlength="20"> </lable> </td> </tr> <tr> <td>评论:</td> <td align="center"> <textarea name="comment" id="comment" rows="6" cols="30"></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <lable> <input type="button" name="submit" value="发表" id="submit" onclick="addcomment();"/> </lable> <lable> <input id="divmsg" name="divmsg" value="" readonly /> </lable> </td> </tr> </table> </form></body></html>
问题已解决,就是版主说的错误。提交时三个不同的变量之间用&相隔,因为刚刚接触AJAX,所以对POST提交不是很了解。

负载均衡会影响会话管理,但可以通过会话复制、会话粘性和集中式会话存储解决。1.会话复制在服务器间复制会话数据。2.会话粘性将用户请求定向到同一服务器。3.集中式会话存储使用独立服务器如Redis存储会话数据,确保数据共享。

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

PHP会话的替代方案包括Cookies、Token-basedAuthentication、Database-basedSessions和Redis/Memcached。1.Cookies通过在客户端存储数据来管理会话,简单但安全性低。2.Token-basedAuthentication使用令牌验证用户,安全性高但需额外逻辑。3.Database-basedSessions将数据存储在数据库中,扩展性好但可能影响性能。4.Redis/Memcached使用分布式缓存提高性能和扩展性,但需额外配

Sessionhijacking是指攻击者通过获取用户的sessionID来冒充用户。防范方法包括:1)使用HTTPS加密通信;2)验证sessionID的来源;3)使用安全的sessionID生成算法;4)定期更新sessionID。

本文比较了PHP和ASP.NET,重点是它们对大规模Web应用程序,性能差异和安全功能的适用性。两者对于大型项目都是可行的,但是PHP是开源和无关的,而ASP.NET,


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版
中文版,非常好用

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具