我试图通过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');
}
});
Run Code Online (Sandbox Code Playgroud)
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 …
Run Code Online (Sandbox Code Playgroud)