@mclaughlinj I am also trying to do same as you. I have url which opens an email. I can execute that in browser but not through Get method of http client as it uses javascript. In my case I dont know which java script function or code is executed to open that url. Could you pl tell me how do I trace that code ? because I dont know java script.
–
RaginiJul 5 '12 at 9:24

This made my day. Sometimes, good old javascript works way better than all the frameworks.
–
motiverJan 24 '13 at 22:17

23

Actually, that feature is not built into any of the ECMAScript implementations, but it is provided by the host environment through a (now formally specified) API that has an ECMAScript binding. BTW, avoid synchronous request-response handling (false) because due to single-threaded execution that will block the user interface until the response has been received or the request timed out.
–
PointedEarsFeb 4 '13 at 11:18

8

Its because nothing at all works in IE (especially not in the old versions) :D
–
GigalaAug 2 '13 at 10:17

note that this isn't working in IE 10 when trying to access url in a different domain than the page's domain
–
BornToCodeSep 30 '13 at 9:35

2

@BornToCode you should investigate further and possibly open up a bug on the jQuery issue tracker in that case
–
ashes999Oct 8 '13 at 16:58

12

Voted down for implementing in jQuery when it could be done in pure JS. Fair enough if jQuery was loaded already, but very bad practice using a huge library just for a get.
–
SamJan 1 '14 at 14:47

10

I know some people want to write pure Javascript. I get that. I have no problem with people doing that in their projects. My "In jQuery:" should be intpreted as "I know you asked how to do it in Javascript, but let me show you how you would do that with jQuery, that you might have your curiosity piqued by seeing what kind of syntax conciseness and clarity you can enjoy by using this library, which would afford you numerous other advantages and tools as well".
–
PistosJun 26 '14 at 19:47

Since this answer is one of the top results for googling "http request javascript", it's worth mentioning that running eval on the response data like that is considered bad practice
–
KloarMay 19 '14 at 9:47

Because "anHttpRequest" isn't prefixed with "var" in the above, it becomes global. So you create another instance, such as "bCient = new HttpClient()" it will overwrite the existing global instance. Chaos will ensue. Danger!
–
Jay BorsethNov 18 '14 at 19:29

IE will cache URLs in order to make laoding faster, but if you're, say, polling a server at intervals trying to get new information, IE will cache that URL and will likely return the same data set you've always had.

Regardless of how you end up doing your GET request - vanilla JavaScript, Prototype, jQuery, etc - make sure that you put a mechanism in place to combat caching. In order to combat that, append a unique token to the end of the URL you're going to be hitting. This can be done by:

var sURL = '/your/url.html?' + (new Date()).getTime();

This will append a unique timestamp to the end of the URL and will prevent any caching from happening.

The problem is that Mac OS X doesn't come with Prototype pre-installed. As the widget needs to run in any computer, including Prototype (or jQuery) in each widget is not the best solution.
–
kiamlalunoAug 7 '10 at 5:05

The best way is to use AJAX ( you can find a simple tutorial on this page Tizag). The reason is that any other technique you may use requires more code, it is not guaranteed to work cross browser without rework and requires you use more client memory by opening hidden pages inside frames passing urls parsing their data and closing them.
AJAX is the way to go in this situation. That my two years of javascript heavy development speaking.

If you want to use the code for a Dashboard widget, and you don't want to include a JavaScript library in every widget you created, then you can use the object XMLHttpRequest that Safari natively supports.

As reported by Andrew Hedges, a widget doesn't have access to a network, by default; you need to change that setting in the info.plist associated with the widget.

<pre>
You can get HTTP GET request in two ways:
1) xmlhttp.open("GET","URL",true);
xmlhttp.send();
This approach based on xml format.
Here you have to pass url for the request.
2) $("btn").click(function()
{
$.ajax({url:"demo_test.txt",success:function_name(result)
{
$("#innerdiv").html(result);
}});
});
This one based on the JQuery.
Here you have to specified url and function_name to which you want to call
</pre>