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.com/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?
JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.
Both of these are computer languages that help in programming, but there is a major difference between JavaScript and HTML. While JavaScript (abbreviated as JS) is a scripting language, HTML is a markup language. We use HTML to create web pages or web applications.
For those want to learn to program, one of the biggest advantages of JavaScript is that it is all free.
JavaScript simply adds dynamic content to websites to make them look good. HTML work on the look of the website without the interactive effects and all. HTML pages are static which means the content cannot be changed. It adds interactivity to web pages to make them look good.
It 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.com/bar.php
resolves to
http://www.foo.com/new_dir/index.php?r=blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With