• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Ajax对象 向 服务器发送数据请求的有关问题 新手求解答

php 搞代码 3年前 (2022-01-23) 13次浏览 已收录 0个评论

Ajax对象 向 服务器发送数据请求的问题 新手求解答。
问题出在 文件 Ajax.html 向 文件 server.php 发送数据请求。。

以下是 Ajax.html 代码:

HTML code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><script>            function  createAjax(){            var Ajax=false;            if(window.XMLHttpRequest){            //非IE系列,符合W3C标准,或者是IE7,IE8                    Ajax=new window.XMLHttpRequest();                        if(Ajax.overrideMimeType){                    Ajax.overrideMimeType("text/xml");            }                         }else if(window.ActiveXObject){            //IE系列的低版本                    var version=['Microsoft.XMLHTTP','MSXML.XMLHTTP','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP'];                        for(var i=0;i<version<i>*本5文来源gaodai$ma#com搞$$代**码)网@</i><img>搞代码gaodaima</img>.length;i++){                        try{                           Ajax=new ActiveXObject(version[i]);                                    if(Ajax){                                            return Ajax;                                            }                           }                        catch(e){                           Ajax=false;                        }                                              }                                }                         return Ajax;            }                        var Ajax=null;            function show(){                   Ajax=createAjax();                   Ajax.open("post","server.php?name=tianxiaokang&age=22&"+Math.random(),ture);                   Ajax.send(null);            }            </script>            

这个是 server.php 代码:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php      $str=$_GET["name"];      $str.="*******";      $str.=$_GET["age"];            $file=fopen("save.txt","a");      fwrite($file,$str);      fclose();      ?>

为什么我的根目录生成不了 save.txt 文件。。

——解决方案——————–
将ajax的传递方式改为get
——解决方案——————–
Ajax.open(“get”, “server.php?name=tianxiaokang&age=22&”+Math.random(),true);


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Ajax对象 向 服务器发送数据请求的有关问题 新手求解答
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址