Jump to:

23367 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Rendering Content as XML for AJAX

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1534 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Rendering Content as XML for AJAX Link to this post

    I'm trying to create an AJAX image switcher for different Colored Product.

    In my Page_Controller id added

    if(Director::is_ajax() || $_GET["ajaxDebug"]) {
             $this->isAjax = true;
             }
             else {
                $this->isAjax = false;
                }

    Then in my ColorProduct Page Controller I added:

    function index() {
    if($this->isAjax) {
    return $this->renderWith("ColorProductXML");
    }
    else {
    return Array();
    }
    }

    I then created a ColorProductXML tempalte and placed it in my root template directory

    <?xml version="1.0" encoding="UTF-8"?>
    <colorproduct>
       <% control Colors %>
       <color colorID="$StripColorName">
          <name>$ColorName</name>
          <hex>$ColorHex</hex>
          <% control ToyImageClasss %>
          <imagegroup imageName="$StripImageName">
             <type>$ImageClass</type>
             <% control ToyImages %>
                <% if Type=="Normal" %>
                   <% control Attachment %>
                      <thumbnail>$SetWidth(60).URL</thumbnail>
                      <small>$SetWidth(460).URL</small>
                      <zoom>$SetWidth(920).URL</zoom>
                      <full>$URL</full>
                   <% end_control %>
                <% end_if %>
                <% if Type=="Blur" %>
                   <blur>$Attachment.URL</blur>
                <% end_if %>
             <% end_control %>
          </imagegroup>
          <% end_control %>
       </color>
       <% end_control %>
    </colorproduct>

    When I access a ColorProduct page adding ?ajax=1 to the end of my URL I get nice XML document, and my jQuery call to that url also returns a document in the same format but I can't query the nodes. Firebug shows the Content-Type as text/html instead of application/xml. How do I force SS to return an XML content type?

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Rendering Content as XML for AJAX Link to this post

    After a few more fruitless hours of digging I decided to copy the contents of the page with ?ajax=1 variable added and paste it into a static xml file. When my jQuery script loads THAT file i notice when I dump it i see the <?xml version="1.0" encoding="UTF-8"?> header at the top of the results but not from the "live" version

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Rendering Content as XML for AJAX Link to this post

    Any ideas? Enabling API access will give me an XML of the table, but I need access to resized image URLs

    1534 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.