前端 $.post 請求 demo_test_post.asp,預期獲取純文本響應,實際返回整個 ASP 源碼(含 <% %> 標籤)。根因:伺服器未執行 ASP 腳本,直接當靜態文件返回。
// 前端
$.post("demo_test_post.asp", {name:"Donald", city:"Duckburg"}, function(data){
alert(data); // 彈出整個 ASP 源碼
});
// ASP 文件 demo_test_post.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
dim fname, city
fname = Request.Form("name")
city = Request.Form("city")
Response.Write("Dear " & fname & ". Hope you live well in " & city & ".")
%>
.asp 文件,雙擊或瀏覽器直接打開 → 當文本文件讀取asp.dll 解析執行 <% ... %>file:// 協議)不會觸發 ASP 引擎asp.dll 註冊:regsvr32 %windir%\system32\inetsrv\asp.dlldemo_test_post.asp 的資料夾
https://localhost:8080/demo_test_post.asp?name=Donald&city=Duckburg
// 應顯示:Dear Donald. Hope you live well in Duckburg.
$.post("https://localhost:8080/demo_test_post.asp",
{name:"Donald", city:"Duckburg"},
function(data){ alert(data); });
Content-Type: text/html; charset=gb2312 表示 ASP 執行了;text/plain 或直接看到源碼表示未執行%windir%\System32\LogFiles\W3SVC1\$.post 返回 ASP 源碼 = 伺服器未解析執行 ASP。必須在 IIS 下以 https:// 協議訪問,而非文件系統路徑。新手建議直接學習 ASP.NET Core 或現代後端框架,避開經典 ASP 環境配置坑。