As you point out this is impossible if $a \not \mid b $.
So express $a =\prod p_i^{k_i} $ as its unique prime factorization. Then $b=\prod q_j^{m_j}\prod p_i^{k_i+l_i} $ as its unique prime factorization. As $a|b $ we know the $p_i $ in both factorization are the same set of primes, the $q_i $ (if any) are primes dividing $b$ but not $a $. And each $l_i \ge 0$.
So $x$ can be any $x=\prod q_j^{n_j}\prod p_i^{k_i + h_i} $ where $0\le n_j \le m_j$ and $0\le h_i \le l_i $.
So there are $\prod (m_j+1)\prod (l_i +1) $ possible answers.
Example: $a=36$ and $b=720$ then $a=2^2*3^2$ and $b=5*2^4*3^2$ so there are $(1+1)((4-1)+1)((2-2)+1)=2*3*1=6$ possible $x$s. They are $x=5^a2^{2+b}3^2$ where $a=0,1$ and $b=0,1,2$. So $x $ may be $36,72,144,180,360,720$.
===
Oh....DUH! let $c=b/a $. Let $y$ be a factor of $c $. Then $x=a*y$ are the solutions. So there are as many $x$ as there are factors of $c $. And if $c=\prod p_i^{k_i} $ there are $\prod (k_i+1) $ factors of $c$.
So for the example $a=36$ and $b=720$ then $c=b/a =20=2^2*5$. And $c $ has $(2+1)(1+1)=6$ factors. They are: $1,2,4,5,10,20$. So there are $6$ $x $s. They are $1*36,2*36,4*36,5*36,10*36,20*36=36,72,144,180,360,720$.