location.hostname vs location.host
by Francis[ Edit ] 2013-01-29 18:41:41
location.hostname vs location.host
// Display Domain name and Port Number
location.host == "http://easycalculation.com:8080"
// Display Domain name only
location.hostname == "http://easycalculation.com"
Usage of hostname
Most of ajax post method we used path name. That time we use this hostname the file path error most of time to solve,
For an example, (login issues, like www. or without use www.)
Syntax,
var ajurl = "http://"+location.hostname+"/path/filename.php";
var datas = "val=text";
$.ajax({
type:"POST",
url:ajurl,
data:datas,
success:function(html)
{
alert(html);
}
});
Note :
Instead of
location.hostname we used,
document.domain