Unstoppable Domains

XML/XSLT/AJAX vs. PHP/MySQL/AJAX ?

Spaceship Spaceship
Watch

sky

Established Member
Impact
40
Why would someone tend to use XML / XSLT to transform a bunch of XML data into HTML (to drop into a div) via an AJAX call, vs. using PHP to convert data from a SQL database into HTML, and load that instead into a div via an AJAX call?

Wouldn't these two mechanisms be roughly equivalent?
When would one be preferred over the other and why?

I'm guessing is that the time to use XML / XSLT over PHP / MySQL would be if there was other data that needed to be loaded into javascript variables for client-side processing. But even though it seems that the HTML brought over by AJAX could be parsed as part of the DOM by JavaScript.

Hope my questions are clear enough.

I'm new to XML / XSLT, just starting to learn it, so any insights here would be appreciated. Thanks in advance.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
If you use purely XML and XSLT there is nothing dynamic about the page, you are 100% tied to what is in them.

Are you sure you are not getting confused. Even if you use PHP with AJAX you tend to use it in conjunction with XML (i this case the XML being generated by a PHP script))
 
1
•••
peter@flexiwebhost said:
If you use purely XML and XSLT there is nothing dynamic about the page, you are 100% tied to what is in them.

Are you sure you are not getting confused. Even if you use PHP with AJAX you tend to use it in conjunction with XML (i this case the XML being generated by a PHP script))

I could be getting confused. I've used PHP and Javascript (pretty familiar with those). Now, just starting to work with XMLHttpRequest() [previously I'd sort of homebrewed AJAX-like calls with Js,PHP and iFrames.

So that makes sense to customize the XML with PHP, and now that you mention it, I've seen an example of that. But why XML, why not just bring PHP built HTML across with XMLHttpRequest() everytime? The only example of XSLT I've seen and used does the transformation to HTML before it gets to the browser. The XML file refers to the .xsl file, and the browser gets HTML. So why even bother with XML and XSLT? Why not just use PHP to get HTML and whalla!
 
0
•••
The X in AJAX actually stands for XML (Asynchronous Javascript And XML).

AJAX is meant to be used with XML as it brings uniformity to the equation, you can as you have been doing output plain HTML from the PHP if you wish but XML brings a method of reliability on the received data. Another benefit is say for example you wish to use information that receives the same data but you wish it to be displayed differently, if the PHP script outputs HTML then you would have to either return a flag to the server to say which output format you was expecting or create another script to output it the way you wish. If you use XML then you can use the Javascript to handle what it does with the data.
 
0
•••
peter@flexiwebhost said:
The X in AJAX actually stands for XML (Asynchronous Javascript And XML).

AJAX is meant to be used with XML as it brings uniformity to the equation, you can as you have been doing output plain HTML from the PHP if you wish but XML brings a method of reliability on the received data. Another benefit is say for example you wish to use information that receives the same data but you wish it to be displayed differently, if the PHP script outputs HTML then you would have to either return a flag to the server to say which output format you was expecting or create another script to output it the way you wish. If you use XML then you can use the Javascript to handle what it does with the data.

The latter (javascript parsing the XML) sounds more dynamic then, and possibly quicker depending on how much processing has to take place, and whether the processing load is better consolidated server side or distributed to the clients.

The only XLST example I've viewed so far (I will view more, I'm just ramping up now), shows an XML web page referring to an XSL document, such that the very process of fetching it converts it to HTML. Can you steer me to the common mechanisms used to not only fetch XML data in JavaScript but to parse it and load it into JavaScript variables and arrays, etc?

Thanks!
 
0
•••
Take a look at http://www.w3schools.com/ajax/ajax_xmlhttprequest.asp which should point you in the right location.

Just a note, if looking for tutorials you can follow any tutorial meant for any server side language as the main bit you are concerned with is client side.
 
Last edited:
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back