admin管理员组文章数量:1287645
If I use relative paths in Javascript to GET a page from a server (to display output inside a div), does Javascript use the same protocol/port as the page in which it was loaded?
For example:
parent page is requested .php
JS code on bar.php:
var turl = "/new_dir/index.php?r="+r;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",turl,false);
xmlhttp.send(null);
Since the parent page was requested and served using https on port 443 does this mean that JS will send the GET request to the new page using the same protocol and port? Or will it send the request via http on port 80 since I did not specify a connection protocol in the 'turl' variable?
If I use relative paths in Javascript to GET a page from a server (to display output inside a div), does Javascript use the same protocol/port as the page in which it was loaded?
For example:
parent page is requested https://www.foo./bar.php
JS code on bar.php:
var turl = "/new_dir/index.php?r="+r;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",turl,false);
xmlhttp.send(null);
Since the parent page was requested and served using https on port 443 does this mean that JS will send the GET request to the new page using the same protocol and port? Or will it send the request via http on port 80 since I did not specify a connection protocol in the 'turl' variable?
Share Improve this question asked Feb 3, 2011 at 15:49 mr.dancranemr.dancrane 711 gold badge1 silver badge3 bronze badges 1- It will inherit, try it out, you can sue fiddler to see where request are being sent or you can just use firefox with firebug and look in the nettab. – Martin Jespersen Commented Feb 3, 2011 at 15:53
1 Answer
Reset to default 7It will use the same port and protocol, since you haven't specified anything else. Your URL is a relative reference in RFC-speak, details in Section 4.2 of the RFC. (I only happen to know the RFC section reference because I just recently found out about this nifty trick for http/https stuff.)
So your request for
/new_dir/index.php?r=blah
relative to the document
http://www.foo./bar.php
resolves to
http://www.foo./new_dir/index.php?r=blah
版权声明:本文标题:Javascript & https - XMLHttpRequest object to GET relative path - is protocolport 'inherited'? - Stack O 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741278571a2369874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论