I have an object I built in Javascript that I want to pass into a .NET .ASHX file and then parse out the various object properties.
Here is the object I built in Javascript:
function passSelection(prop1, prop2, prop3, prop4, prop5, prop6) {
this.prop1 = prop1value;
this.prop2 = prop2value;
this.prop3 = prop3value;
this.prop4 = prop4value;
this.prop5 = prop5value;
this.prop6 = prop6value;
};
Then I populate the object with values;
var javascriptObject = new passSelection(var1, var2, var3, var4, var4, var6);
Then I call my ajax function to send the object to the .ASHX;
nameOfAjaxFunction(javascriptObject);
This all works well. But now inside the .ASHX I want to get the individual properties of the object so I set a .NET variable to the javascriptObject in my AJAX querystring. This also seems to work fine.
Dim objObjectVariable = context.Request.QueryString("javascriptObject")
So the question is: Now that I have a .NET variable set to the javascript object how do I reference the individual object properties?
Any hints or suggestions would be greatly appreciated. Thanks!
With Ajax you’ll be always sending strings to the server, not objects. In your case,
nameOfAjaxFunctionseems to be passing it via GET (POST would be the other option). The best way to pass an object is to encode it as JSON on your JS (from withinnameOfAjaxFunction), then decode it back at the server end.