views:

154

answers:

1
$.post("test.php", { name: "John", time: "2pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

The object { name: "John", time: "2pm" } is anonymous. Normally, I would access the properties of an object using syntax similar to the following:

objectname.propertyname

But what can I do when there is no objectname? How can I access propertyname?

A: 

The whole point of an anonymous object is that it is just that, anonymous. It is accessed in context only. If you want to access the object later on, then you need to assign the object to a variable.

Try:

var obj = { name: "John", time: "2pm" };
$.post("test.php", obj,
  function(data){
    alert("Data Loaded: " + data);
    alert("obj name is " + obj.name);
  });
zombat