you have to use jquery utility functions like $.get
or $.ajax
with type as GET
.
If you are able to get result in browser url, then the result is coming for a GET
request and here in jquery
code you are making a post request.
UPDATED TO COMMENTS
"Origin null is not allowed by Access-Control-Allow-Origin."
This issue comes when you are probably making a ajax request to a page in another domain or when you load the page directly via double clicking on it without going through the host url.
ie instead of file:///
in url address you should have same domain name on which the php page you are requesting.
IF YOU ARE MAKING A CROSS DOMAIN AJAX REQUEST
If your ajax request target page lies in another domain, you can do a Cross domain ajax request
you should set
Access-Control-Allow-Origin: *
header on your server which hosts the ajax target page. Setting the value to *
means it will allow requests from any domain, so it makes security venerable as mentioned here.
also at the client end you may use Jquery.ajax utility function with the crossDomain
setting set to true. Also this will have issues that it wont work in IE versions.
see some related question describing this issue.
this article on jquery docs, discusses the same issue and has a suggestion mentioned via including a js fix file which i have tried myself before and got working.
Below are some related links for setting the CORS support in various servers and doing the ajax call at client side.
add CORS support to my server
use CORS from JavaScript