Jump to content

XmlHttpRequest vs script src


Drakim

Recommended Posts

I was wondering if anybody knows the pros and cons for doing AJAX with the XmlHttpRequest object against the pros and cons of using the <script type="text/javascript" src="whatever.php"></script> metod?

What I know is:
The latter one does not require an object, therefore IE 6 users won't have to use the an ActiveX control and get a warning, and it would also work in some other older browsers that doesn't have the object at all.

But, is it as fast? Does it offer as much functionality?
Link to comment
Share on other sites

I think you're missing the point.  You can't do: <script type="text/javascript" src="whatever.php"></script>

That's not legal syntax.  Also, the whole point in using AJAX is to talk to the server without reloading the page.  You can't do that strictly with Javascript. 

Also, users don't get an "ActiveX" control warning if you're using the JS call to the object.  You're not actually downloading a control to the user's computer.  You're just using an ActiveX object that is built into the browser.
Link to comment
Share on other sites

  • 2 years later...

I think you're missing the point.  You can't do: <script type="text/javascript" src="whatever.php"></script>

 

That's not legal syntax.  Also, the whole point in using AJAX is to talk to the server without reloading the page.  You can't do that strictly with Javascript. 

 

Also, users don't get an "ActiveX" control warning if you're using the JS call to the object.  You're not actually downloading a control to the user's computer.  You're just using an ActiveX object that is built into the browser.

 

This syntax is totally legal and such a script object can be used to perform asynchronous http requests as well as an xmlhttprequest can do.

Link to comment
Share on other sites

You can do AJAX without any XMLHttpRequest object. Instead, you can use an other data transportation pattern: dynamically loaded javascript thanks to the 'script' tag and its 'src' attribute. This transportation pattern is usually associated with the JSON format (even though you can wrap XML as well) and it is sometimes considered as more powerfull than the XMLHTTPRequest object since it allows AJAX applications to perform cross-domain requests. Some service providers such as Google or Yahoo use this pattern thus making it possible to establish connections to their servers inside your AJAX application.

There are tones of articles that tackle this subject on the internet. Google is your friend.

Link to comment
Share on other sites

jsonp is precisely based on the use of the src attribute.

Of course for locally calls one should use an XMLHttpRequest object (in certain cases though the <script> pattern may be more appropriate (long polling requests is an example)).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.