以下是我的2个js文件。
ajaxintro.js:
var xmlHttp;
function S_xmlhttprequest(){
    if(window.ActiveXObject){
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else if(window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();
    }
}function funphp101(url){
   S_xmlhttprequest();
   xmlHttp.open("GET","introduction.php?id="+url,true);
   xmlHttp.onreadystatechange = byphp1;
   xmlHttp.send(null);
   }function byphp1(){
   var byphp101 = xmlHttp.responseText;
   document.getElementById("intro").innerHTML = byphp101;}ajaximages.js
var xmlHttp;
function M_xmlhttprequest(){
    if(window.ActiveXObject){
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else if(window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();
    }
}function funphp102(url){
   M_xmlhttprequest();
   xmlHttp.open("GET","imagestest.php?id="+url,true);
   xmlHttp.onreadystatechange = byphp2;
   xmlHttp.send(null);
   }function byphp2(){
   var byphp102 = xmlHttp.responseText;
   document.getElementById("images").innerHTML = byphp102;
   alert("imagesuccess");
}
然后<script type="text/javascript"  src="ajaxintro.js" src="ajaximages.js"></script>,结果是系统只执行ajaxintro.js。如果写成<script type="text/javascript" src="ajaximages.js" src="ajaxintro.js" ></script>,它就执行ajaximages.js。
我的目的是两个都执行,求解答

解决方案 »

  1.   

    第一个js文件中已经定义了一个名为:xmlHttp的var xmlHttp;
    第二个js文件中换一个名称,不能有重复的
      

  2.   

    在网上下一个ajax的文件吧。
    你这个问题太多。
      

  3.   

    全文的xmlHttp都改掉还是不行。理论上函数不重复,自变量不重复,应该是没问题的啊
      

  4.   

    <script type="text/javascript" src="ajaxintro.js"></script>
    <script type="text/javascript" src="ajaximages.js"></script>
      

  5.   

    jquery没接触过,主要是不知道我现在的代码问题在哪里,很想把它搞清楚。
      

  6.   

    不起作用啊,而且这个和<script type="text/javascript" src="ajaxintro.js" src="ajaximages.js"></script>有区别吗?
      

  7.   


    ajaxintro.js:
    function S_xmlhttprequest(){
      var xmlHttp;
      if(window.ActiveXObject){
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } else if(window.XMLHttpRequest) {
      xmlHttp = new XMLHttpRequest();
      }
      return xmlHttp;
    }function funphp101(url){
      xmlHttp=S_xmlhttprequest();
      xmlHttp.open("GET","introduction.php?id="+url,true);
      xmlHttp.onreadystatechange = function(){byphp1(xmlHttp);};
      xmlHttp.send(null);
      }function byphp1(xmlHttp){
      var byphp101 = xmlHttp.responseText;
      document.getElementById("intro").innerHTML = byphp101;}ajaximages.js
    function M_xmlhttprequest(){
       var xmlHttp;
      if(window.ActiveXObject){
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } else if(window.XMLHttpRequest) {
      xmlHttp = new XMLHttpRequest();
      }
      return xmlHttp;
    }function funphp102(url){
      xmlHttp=M_xmlhttprequest();
      xmlHttp.open("GET","imagestest.php?id="+url,true);
      xmlHttp.onreadystatechange = function(){byphp2(xmlHttp);};
      xmlHttp.send(null);
      }function byphp2(xmlHttp){
      var byphp102 = xmlHttp.responseText;
      document.getElementById("images").innerHTML = byphp102;
      alert("imagesuccess");
    }
    调用:
    <script type="text/javascript" src="ajaxintro.js"></script>
    <script type="text/javascript" src="ajaximages.js"></script>
    有多个src浏览器只会解析一个src
    <script type="text/javascript" src="ajaxintro.js" src="ajaximages.js"></script>
      

  8.   

    用jquery来做ajax,相当方便!$.ajax({
       type: "POST",
       url: "test.php",
       data: "id=1&user=tom",
       cache: false,
       success: function(response){
         $('#msg').html(response);
       }
    }); 
      

  9.   


    function funphp101(url){
      S_xmlhttprequest();
      xmlHttp.open("GET","introduction.php?id="+url,true);
      xmlHttp.onreadystatechange = byphp1;
      xmlHttp.send(null);
      }
    function funphp102(url){
      S_xmlhttprequest();
      xmlHttp.open("GET","imagestest.php?id="+url,true);
      xmlHttp.onreadystatechange = byphp1;
      xmlHttp.send(null);
      }
    现在发现了问题,我的触发器是<a href="#" onclick="funphp101('')"></a>.所以只调用了funphp101函数,请问我该怎么把funphp101和funphp102上面两个函数的功能写在一个函数里面?
      

  10.   

    <script type="text/javascript" src="ajaximages.js" src="ajaxintro.js" ></script>
    一次可以导入两个js文件吗??
    如果可以,你可以完全将
    var xmlHttp;
    function M_xmlhttprequest(){
      if(window.ActiveXObject){
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } else if(window.XMLHttpRequest) {
      xmlHttp = new XMLHttpRequest();
      }
    }
    提取出一个function 就OK了啊...
    没有必要两个页面都写.
      

  11.   


    可以把两个函数要实现的功能写到一个里面,只要一次ajax交互就可以了,不过需要后台在一个PHP文件里处理那两个方法的逻辑,然后一次性返回。