I want to create several objects that are local to a specific function, but I want another function to act as a helper. The purpose of the helper function is to reduce the amount of duplicate code (there will eventually be many objects created as the script progresses).
I 'boiled down' my script, made sure it works, and then copy/pasted it below. The function named 'foo' works (there is an php file not shown for the jQuery/ajax call). However, I want the ajax call to be in the getNode function (the helper function) and preferably the setting of a temporary object also in getNode. My thinking is that a temporary object could be passed to foo from getNode.
<script type="text/javascript">
function Node() {
this.nodeId;
this.type; //can be used for diferent shapes, color cobinations, etc.
this.text;
}
function getNode(id){
$.post("updateDB.php", send, function(theResponse){
var responseArray = theResponse.split(',');
....?
}
function foo(id){
var centerNode = new Node();
var send = 'id=' + id + '&action=getNode';
$.post("updateDB.php", send, function(theResponse){
var responseArray = theResponse.split(',');
centerNode.nodeId = responseArray[0];
centerNode.type = responseArray[1];
centerNode.text = responseArray[2];
alert('nodeId' + centerNode.nodeId);
alert('node type' + centerNode.type);
alert('node text' + centerNode.text);
});
}
</script>
</head>
<body>
<a onclick="foo(5)">test</a>
</body>