在ASP中读取自定义POST主体

时间:2009-09-29 20:34:26

标签: ajax json prototypejs

我正在使用Prototype 1.6.1为页面创建POST。 POST数据是一个复杂的JSON对象。有人能告诉我如何在接收页面上访问POSTed数据的原始主体吗?

发送页面:

myObject = {"key":"val",
            "has many":{"key1":"val1",
                        "key2":"val2"}
           }

new Ajax.Request('Worker.asp',
{
    method:"post",
    postBody:Object.toJSON(myObject),
    onSuccess: function(transport){
    var response = transport.responseText || "no response text";
    alert("Echo'ing back what you sent: \n\n" + response);
},
 onFailure: function(){ alert('Something went wrong...') }
});

这就是发送页面。创建一个对象和一个请求。我已经使用FireBug来确保发送的POST数据看起来像我想要的样子。

现在在目标页面上,我无法访问POSTed数据。我尝试了以下,但它没有用。

接收页面:

<% Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes)) %>

但是我收到服务器错误500.所以基本上,我想知道如何使用我发布的内容。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

好吧,我想我已经拥有了它:我试图强迫自己处理不好的事情,当她真正想要的就是像女士一样对待。我没有让我的POST数据只是JSON“text”,而是将其作为参数:

new Ajax.Request('StageWorker.asp',
{
 method:"post",
 //postBody:Object.toJSON(AllStageInfo),  //<-- THIS DIDN'T WORK
 parameters:{alldata:Object.toJSON(AllStageInfo)}, //<-- THIS DID
 onSuccess: function(transport){
   var response = transport.responseText || "no response text";
   alert("Success! \n\n" + response);
   },
 onFailure: function(){ alert('Something went wrong...') }
});

接收页面只是:

Response.Write( Request.Form("alldata"))

tada,请求通过我发送的内容提醒了我。