Rod Rod - 1 month ago 10
Ajax Question

Why is my parameter null when I try to pass object using MS AJAX PageMethods

I tried the following snippet as well:

PageMethods.MyMethod(JSON.stringify(person), OnMyMethodComplete);


Client markup:

</form>
<script type="text/javascript">
var person = { firsName: "World" };
function test() {
PageMethods.MyMethod(person, OnMyMethodComplete);
}

function OnMyMethodComplete(result) { alert(result); }

window.onload = function () {
test();
};
</script>
</body>
</html>


Code-behind:

[WebMethod]
public static string MyMethod(Person p)
{
return "Hello " + p.FirstName;
}


Debug:
enter image description here

Rod Rod
Answer

I was defining var Person in client code, but looking for var p on the server-side.