I've never passed a JavaScript object to an .asp page. Can someone give me the syntax here. I've tried googling w/o success. The object is called buyerInfo. Using jQuery.
<form id="aform" action="formact.asp" method="POST">
<input type="hidden" id="myhid" name="myhid" value="">
<input type="submit">
</form>
<script>
buyerInfo = {};
buyerInfo.name = "Joe Buyer"
buyerInfo.zip = "12345"
$("#myhid").val(buyerInfo);
</script>
-- and in formact.asp
<%
Set buyer = Request("myhid")
name = buyer.name
%>
yields Object doesn't support this property or method: 'buyer.name'.
What is the correct way to reference these? I know the JavaScript object is being passed, but I don't know how to access its pieces. Thanks.
Response.Write(buyer)was anything other than the string "[object Object]". You should stringify the javascript object then see this question re using JSON in ASP/vbscript : stackoverflow.com/questions/12153925/…toString()a full JavaScript object you get "[object Object]" : jsfiddle.net/70rLdxsg . This is what is happening here as form fields can only contain strings, the object is automatically "toStringed". You need some way of serialising the object on the client end then deserializing it on the server end. JSON is one method that is easy in the borwser, not so much in classic ASP. If the object is pretty simple, I'd just have a hidden field for each property on the object.