2011-02-18 77 views
0

我創建了一個按鈕,就像在網頁瀏覽器上點擊時應該執行一個asp文件一樣。我不知道爲什麼我的xmlhttp請求沒有被髮送。我試圖在本地主機上,但仍然沒有任何工作!代碼去按鈕,即點擊即JavaScript是這樣的!xmlhttp請求

CustomButton = { 

1: function() 
{ 

var xmlhttp; 
if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
    {// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText; 
    } 
    } 
xmlhttp.open("GET","http://localhost/Default.asp",true); 
xmlhttp.send(); 
    } 
} 

我使用htdocs文件夾,其中Default.asp文件是的Default.asp的located.The代碼

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication9._Default" %> 

<!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 runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <% 
="Hello World!" 
%> 
     </form> 
</body> 
</html> 

爲什麼這個代碼不工作????

回答

0

嘗試在Firefox上使用Firebug腳本調試器的幫助來調試代碼。

你也可以通過在Firefox中使用Http Fox Addon來分析請求和響應。

通過使用這個,你可以看到你的請求是否去正確的文件。 也會有什麼反應。