Ajax Post方法不工作!!帮帮我

Ajax Post method not working !! Help me out

本文关键字:工作 Post 方法 Ajax      更新时间:2023-09-26

下面是我的代码,其中包括一个ajax调用与包含jquery库。

 <!DOCTYPE html>
 <html>
 <head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
 $.post("index4.asp",
 {
   name:"Donald Duck",
   city:"Duckburg"
 },
 function(data,status){
   alert("Data: " + data + "'nStatus: " + status);
 });
 });
 });
 </script>
 </head>
 <body>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>

下面是我的'index4.asp'文件的代码

<%
dim fname,city
fname=Request.Form("name")
city=Request.Form("city")
Response.Write("Dear " & fname & ". ")
Response.Write("Hope you live well in " & city & ".") 
 %>

My Output是一个警告框,内容为

<%
 dim fname,city
 fname=Request.Form("name")
 city=Request.Form("city")
 Response.Write("Dear " & fname & ". ")
 Response.Write("Hope you live well in " & city & ".") 
  %> 
 with  status = success

而警告框必须是

  Dear DonaldDuck.Hope you live well in Duckburg.
   with status=success

帮帮我!!

可能发生这种情况的一个原因是您没有从服务器运行HTML页面。

查找的简单方法是查看浏览器地址栏中显示的URL。如果它以"file://"开头,那么你做错了。它应该以"http://"开头,以便您当前的代码工作。

现在,如果URL读取"http://",然后如果你仍然得到错误,那么,你正在运行的web服务器不能运行ASP。使用一个可以理解ASP的web服务器。

如果您没有ASP web服务器,请参考http://www.w3schools.com/asp/asp_install.asp了解如何运行。