I'll start by showing one way of achieving this:
variable=`echo ./script_on_remote_server.sh | ssh username@hostname`
Or if you're using bash, I prefer this syntax:
variable=$(echo ./script_on_remote_server.sh | ssh username@hostname)
It's a little difficult to tell from your post, but it looks like you were trying to do the following:
ssh username@hostname <<EOF
variable=./script_on_remote_server.sh
echo $variable
EOF
However, there are a few misunderstandings here. variable=command is not the correct syntax for assigning the output of the command to a variable; in fact, it doesn't even run the command, it merely assigns the literal value command to variable. What you want is variable=`command` or (in bash syntax) variable=$(command). Also, I presume that your goal is to have variable available to the shell on the local machine. Declaring variable in code to be run on the remote machine is not the way to do that. ;) Even if you did this:
ssh username@hostname <<EOF
variable=`./script`
echo $variable
EOF
This is just a less efficient way of running the command on the remote host as usual, because variable gets lost immediately:
echo ./script | ssh username@hostname
Also, note that the ssh command accepts a command to run as an additional argument, so you can abbreviate the whole thing to:
variable=`ssh username@hostname ./script_on_remote_server`