日期:2014-05-18  浏览次数:20442 次

Ajax問題!
請幫我看下哪里出問題.當我點擊按鈕調用CallServer時,狀態欄出現網頁出錯,是不是用Ajax時,要先裝什麼啊??

下邊的代碼寫在TestAjax.js文件里

var xmlHttp;

function CreateXmlHttpRequest()
{
  try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e)
  {
  try
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch(e2)
  {
  xmlHttp=new XMLHttpRequest();
  }
  }
}

function CallServer()
{
  CreateXmlHttpRequest();
  var url="Default.aspx"; //這個網頁有建立的
  xmlHttp.open("Get",url,true);
  xmlHttp.onreadystatechange =test;
  xmlHttp.send(null);
}

 function test()
  {
  //這里啥都不寫也一樣出這問題
  }


------解决方案--------------------
JScript code

    <script type="text/javascript">
        var xmlHttp;
       
        function createXMLHttpRequest()
        {
            if(window.ActiveXObject)
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            if(window.XMLHttpRequest)
                xmlHttp=new XMLHttpRequest();
        }
       
        function zx()
        {
            createXMLHttpRequest();
           
            xmlHttp.open("get","Default2.aspx",true);
            xmlHttp.onreadystatechange=xmlHttpChange;
            xmlHttp.send(null);
        }
       
        function xmlHttpChange()
        {
            if(xmlHttp.readyState==4)
            {
                if(xmlHttp.Status==200)
                {
                    alert(xmlHttp.responseText);
                }
            }
        }
    </script>

------解决方案--------------------
要确保路应用路径正确。
------解决方案--------------------
如下格式:<link href="~js/Ajaxt.cs" type="text/javascript" />
------解决方案--------------------
<link href="~js/Ajaxt.cs" type="text/javascript" />???
是兄弟我孤陋寡闻还是又有新的用法了,还从来没有见过这样用的。我一般都是这样用<script type="text/javascript" src="js.js"></script>