Need to post a hidden form field with jQuery

Need to post a hidden form field with jQuery

I need to fetch a csrf value from a php and post it via a hidden form field using jQuery. My code is here: https://stackoverflow.com/questions/47196897/how-to-have-jquery-to-return-csrf/
What wrong I did there? Any advise is appreciated.