>  기사  >  백엔드 개발  >  Ajax对象 向 服务器发送数据请求的有关问题 新手求解答

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

WBOY
WBOY원래의
2016-06-13 13:37:40998검색

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

以下是 Ajax.html 代码:

HTML code
<!--

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.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>
            <input type="button" onclick="show()" value="请求">

 


这个是 server.php 代码:
PHP code
<!--

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);
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.