javascript how to load an script or data like google without ajax on any event
If i do this code
<script>
$('<img></img>').attr('src', 'someimage.jpg').appendTo($('#div'));
</script>
<div id="div"></div>
I can see GET htpp://somedomain.ext/someimage.jpg
in Net Panel in Firebug.
I think google autocomplete also works pretty much the same way, since there are no asynchronous request, nothing can be seen on firebug console.
开发者_如何转开发Now, is there any object (like img) that i could send http
request to some domain for loading data like google.
UPDATE::
I HONESTLY DON'T SEE A THING IN XHR TAB IN NET PANEL.
WHY AM I SEEING REQEST MADE IN JS TAB IN NET PANEL.
Please correct me if i have misunderstood.
You are looking for the ajax method or one if the convenient front-ends for it: post, get, load, or getScript. There's an entire plugin written around the AJAX calls in jQuery for autocomplete. I'll note that if you are planning to get data from server outside the domain of your web page, you'll need to use JSONP against an API that supports it due to the same origin policy which disallows AJAX requests to other domains. When using JSONP as the result type, jQuery silently turns ajax
, post
, and get
requests into script requests, i.e., adds a script tag with the url and url-encoded parameters to the data source and expects a script back that executes a callback with the returned data.
精彩评论