从发布的JSON获取Classic ASP变量 [英] Get Classic ASP variable from posted JSON

查看:112
本文介绍了从发布的JSON获取Classic ASP变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过AJAX将JSON发布到Classic ASP页面,该页面检索值,检查数据库并将JSON返回到原始页面.

I'm trying to post JSON via AJAX to a Classic ASP page, which retrieves the value, checks a database and returns JSON to the original page.

我可以通过AJAX发布JSON.我可以从ASP返回JSON.我无法将发布的JSON检索到ASP变量中.

I can post JSON via AJAX. I can return JSON from ASP. I can't retrieve the posted JSON into an ASP variable.

POST使用Request.Form,GET使用Request.Querystring. JSON使用什么?

POST you use Request.Form, GET you use Request.Querystring. What do I use for JSON?

我有JSON库,但它们只显示在ASP脚本中创建一个字符串,然后进行解析.在传递外部变量时,我需要解析JSON.

I have JSON libraries but they only show creating a string in the ASP script and then parsing that. I need to parse JSON from when being passed an external variable.

JavaScript

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)

ASP file (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

推荐答案

alphadogg的解决方案对我不起作用,我在bStream.Write requestBody行中出现错误(说在此情况下不允许操作.")为我工作,并返回整个请求字符串.但是,它仅适用于< = 100 KB的请求数据,否则,您将必须弄清楚如何使BinaryRead方法正常工作.

alphadogg's solution didn't work for me, I got errors with the line bStream.Write requestBody (saying "Operation is not allowed in this context.") This seems to work for me, and returns the whole request string. However, it will only work for request data <= 100 KB, otherwise you'll have to work out how to get the BinaryRead method working.

str = Request.Form

(从 http://msdn .microsoft.com/en-us/library/ms525985%28v = VS.90%29.aspx )

这篇关于从发布的JSON获取Classic ASP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆