我正在尝试通过 AJAX 将 JSON 发布到经典 ASP 页面,该页面检索值、检查数据库并将 JSON 返回到原始页面。
我可以通过 AJAX 发布 JSON。我可以从 ASP 返回 JSON。我无法将发布的 JSON 检索到 ASP 变量中。
POST 使用Request.Form,GET 使用Request.Querystring。 JSON 我该用什么?
我有 JSON 库,但它们只显示在 ASP 脚本中创建一个字符串,然后解析它。我需要在传递外部变量时解析 JSON。
JavaScript
var thing = $(this).val();
$.ajax({
type: "POST",
url: '/ajax/check_username.asp',
data: "{'userName':'" + thing + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function() {
alert('success');
}
});
ASP 文件(check_username.asp)
Response.ContentType = "application/json"
sEmail = request.form() -- THE PROBLEM
Set oRS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT SYSUserID FROM dbo.t_SYS_User WHERE Username='"&sEmail&"'"
oRS.Open SQL, oConn
if not oRS.EOF then
sStatus = (new JSON).toJSON("username", true, false)
else
sStatus = (new JSON).toJSON("username", false, false)
end if
response.write sStatus