2011-02-18 80 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来分析请求和响应。

通过使用这个,你可以看到你的请求是否去正确的文件。 也会有什么反应。