I think the problem is with the url;
You are using the absolute path ( http://localhost/gcm_server_files/sample.php
) in URL.
Try to use the relative path of file in the URL (/sample.php) .
See this for more detail on the same origin policy that applies to Ajax request.
http://en.wikipedia.org/wiki/Same_origin_policy
Try this
$.post(
"relative_path_to/sample.php",
{regId: id,message:msg},
function(data){
alert(data);
});