tou*_*4pk 2 asp.net jquery asp-classic
我试图从jQuery ajax调用经典的ASP函数,但它给出了404错误.我想在这个javascript代码中返回jSON中的记录:
$.ajax({
type: "POST",
url: "../dbFile.asp/GetAllRecords",
data: {"Id"="10"},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(textStatus);
},
success: function(result){
alert("success");
}
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
我在asp经典文件中的vb脚本函数是
Function GetAllRecords()
dim cmd, rs
set cmd=Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandType = 4
cmd.CommandText = "GetAllRecords"
set rs=Server.CreateObject("ADODB.Recordset")
set rs=cmd.Execute()
set GetAllRecords= rs
set rs=nothing
set cmd=nothing
End Function
Run Code Online (Sandbox Code Playgroud)
请指导,我被困在这里.
您不能像调用ASP.NET WebMethod那样调用传统的ASP页面.您可以通过在Querystring中传递参数来调用它,例如
url: "../dbFile.asp?Action=GetAllRecords",
Run Code Online (Sandbox Code Playgroud)
并在您的ASP代码中做类似的事情
If Request("Action") = "GetAllRecords"
Response.Write GetAllRecords()
Response.End
End If
Run Code Online (Sandbox Code Playgroud)
注意:为此,您的GetAllRecords()函数需要返回带有JSON或XML的实际字符串,现在它重新创建一个Recordset.您需要循环通过记录集,以正确的格式构建字符串.