Jump to content

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
https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/
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.
  • 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.

AJAX with the XmlHttpRequest

 

and

 

The src attribute in the script tag are not even comparable.

 

Ajax (as said before) is used to refresh certain parts of a page or handling data serverside without leaving a page. The src attribute of the script tag is simply used to include a javascript.

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.

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.