How to fix this issue: If the same code is working on localhost and it is not working on server. It is not the code issue, It is the server issue. You have to talk with hosting provider for getting solution of this issue.
Also you can check it at on your side. For testing it, You have to fire up browsers developer tools and check in the console and network section. You will find, What data is sending and receiving by AJAX.