Add postData function and fix a very subtle bug

Be careful about variable statement using `var`