In the first example, you use an explicit path name. It should be best practice that in production you use an explicit path name from the root or a fully qualified path. It seems to me that the reason your second approach does not work is because it is inferring the path name from the wrong place. It will take the current locale, and then append the url you have. There are a couple possibilities to changing this. Usually what happens is you will have the server pass in a path.
var serverPath = /*get value from server*/;
However, you may also just choose to type in this value explicitly,
var serverPath = "http://mydomain.com/";
which will allow you to use that as a base:
$.get(serverPath + "magic/pages/tcgqueryoutput.php",
function(data, statusTxt){
$('#tcg_query_output').html(data);
});
If you had passed in the serverPath from your server, then you would see this work on both localhost and in production. If you do this manually, you would need to change the value from localhost to mydomain.com.