Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

[SOLVED] Setup an ajax call to load content


Reply


15 Posts   1532 Views

Avatar
ambient

Community Member, 123 Posts

27 May 2014 at 2:52am

Ok the test worked and the string appeared in the container

Is this the response message?
/////////////
Response Headers
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection   close
Content-Length   0
Content-Type   text/html; charset="utf-8"
Date   Mon, 26 May 2014 14:50:30 GMT
Expires   Thu, 19 Nov 1981 08:52:00 GMT
Pragma   no-cache
Server   Apache/2.2.3 (CentOS)
Set-Cookie   bypassStaticCache=deleted; expires=Sun, 26-May-2013 14:50:29 GMT; path=/; httponly PastMember=1; expires=Sun, 24-Aug-2014 14:50:30 GMT; path=/; httponly PastMember=1; expires=Sun, 24-Aug-2014 14:50:30 GMT; path=/; httponly bypassStaticCache=deleted; expires=Sun, 26-May-2013 14:50:29 GMT; path=/; httponly
X-Powered-By   PHP/5.3.3, PleskLin
Request Headers
Accept   text/html, */*; q=0.01
Accept-Encoding   gzip, deflate
Accept-Language   en-US,en;q=0.5
Cookie   vsid=911vr1457306499824979; vsid=904vr1457308991029662; PastMember=1; PHPSESSID=f32h33kbujjledt8al7053ufm6
Host   www.mysite.com
Referer   http://www.mysite.com/our-products/?flush=1
User-Agent   Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
X-Requested-With   XMLHttpRequest
/////////////////

Avatar
Devlin

Community Member, 215 Posts

27 May 2014 at 3:02am

Edited: 27/05/2014 3:02am

This is the response header, there should be more tabs like answer, HTML, preview, response and/or cookies, whichever inspector you're using.

The response answer should be "my test string". With that you can check if the controller method returns html (as in the correct template) and if your data was inserted.

Avatar
ambient

Community Member, 123 Posts

27 May 2014 at 3:08am

Hi Devlin,
Okay cool, yes the response tab shows 'my test string'

So does this mean it's having a problem finding/loading the ProductPage.ss into the container?

Avatar
Devlin

Community Member, 215 Posts

27 May 2014 at 3:20am

$this->renderWith('ProductPage');

I think it's more a problem of rendering data from $this into ProductPage.ss but I don't know what $this is and what ProductPage.ss looks like.

You could try to insert "my test string" in your ProductPage.ss and see what the response answer says.

Avatar
ambient

Community Member, 123 Posts

27 May 2014 at 3:28am

Hi,
The only thing in ProductPage.ss now is 'my test string' and the response is below.
I don't understand the what the $this element is/does.

ERROR [Warning]: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /var/www/vhosts/mysite.com/httpdocs/themes/mytheme/templates/ProductPage.ss
IN GET /our-products/prod1/
Line 388 in /var/www/vhosts/mysite.com/httpdocs/sapphire/core/SSViewer.php

Source
======
379:       if(isset($this->chosenTemplates['main'])) {
380:          $template = $this->chosenTemplates['main'];
381:       } else {
382:          $template = $this->chosenTemplates[ reset($dummy = array_keys($this->chosenTemplates)) ];
383:       }
384:       
385:       if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process", " for $template");
386:       $cacheFile = TEMP_FOLDER . "/.cache" . str_replace(array('\\','/',':'), '.',
Director::makeRelative(realpath($template)));
387:
* 388:       $lastEdited = filemtime($template);
389:
390:       if(!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited || isset($_GET['flush'])) {
391:          if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process - compile", " for
$template");
392:          
393:          $content = file_get_contents($template);
394:          $content = SSViewer::parseTemplateContent($content, $template);

Trace
=====
<ul>filemtime(/var/www/vhosts/mysite.com/httpdocs/themes/mytheme/templates/ProductPage.ss)
line 388 of SSViewer.php

SSViewer->process(ProductPage_Controller)
line 342 of ViewableData.php

ViewableData->renderWith(ProductPage)
line 32 of Page.php

Page_Controller->index(SS_HTTPRequest)
line 193 of Controller.php

Controller->handleAction(SS_HTTPRequest)
line 143 of RequestHandler.php

RequestHandler->handleRequest(SS_HTTPRequest)
line 147 of Controller.php

Controller->handleRequest(SS_HTTPRequest)
line 199 of ContentController.php

ContentController->handleRequest(SS_HTTPRequest)
line 184 of ContentController.php

ContentController->handleRequest(SS_HTTPRequest)
line 67 of ModelAsController.php

ModelAsController->handleRequest(SS_HTTPRequest)
line 282 of Director.php

Director::handleRequest(SS_HTTPRequest,Session)
line 125 of Director.php

Director::direct(/our-products/prod1/)
line 127 of main.php

</ul>

Avatar
ambient

Community Member, 123 Posts

27 May 2014 at 3:38am

Amazing! It's working :)
I had an index function repeated in another page that caused that error.

Thank you so much Devlin, actually I don't think this is the first time you've helped me out.
You rock!!! :)

Avatar
Devlin

Community Member, 215 Posts

27 May 2014 at 3:43am

Well this is an error message we can work with.

Are you sure /var/www/vhosts/mysite.com/httpdocs/themes/mytheme/templates/ProductPage.ss exists and has proper permissions?

I don't understand the what the $this element is/does.
$this is a reference to the current object.

class Car {
   function test() {
      return "Test function called";
   }
   function another_test() {
      echo $this->test(); // This will echo "Test function called";
   }
}

http://www.php.net/manual/en/language.oop5.basic.php