Drakim Posted November 3, 2006 Share Posted November 3, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/ Share on other sites More sharing options...
ober Posted November 3, 2006 Share Posted November 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-119155 Share on other sites More sharing options...
zouip Posted August 14, 2009 Share Posted August 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-898132 Share on other sites More sharing options...
RichardRotterdam Posted August 14, 2009 Share Posted August 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-898148 Share on other sites More sharing options...
zouip Posted August 14, 2009 Share Posted August 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-898180 Share on other sites More sharing options...
RichardRotterdam Posted August 14, 2009 Share Posted August 14, 2009 You're talking about jsonp which is just a way to make cross site data exchange possible with javascript. This is not purpose of the src attribute. If the ajax call is all locally then you don't need this. Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-898185 Share on other sites More sharing options...
zouip Posted August 14, 2009 Share Posted August 14, 2009 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)). Quote Link to comment https://forums.phpfreaks.com/topic/26029-xmlhttprequest-vs-script-src/#findComment-898193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.