Search code examples
jqueryajaxjsonmamp

Unable to load json via ajax with MAMP


I’m trying to build a portfolio with transition à la Medium

So far, I’m able to test it online, but when I launch it locally with MAMP, it won’t load the content. Instead, I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found) jolinmasson.local:8888/ajax/page:6?_=1397435305669

Why is it asking for the wrong url?

Here’s the php/Kirby CMS part of the code:

<?php

$current = $pages->findByUID('home')->children()->visible()->paginate(1);

foreach($current as $p){
  $data['title'] = ((string)$p->title);
  $data['client'] = ((string)$p->client);
  $data['content'] = ((string)kirbytext($p->text));
    if($p->hasImages()){
      $data['image'] = ((string)$p->images()->first()->url());
  };
  $data['projet'] = ((string)kirbytext($p->imagesprojet));
}

echo json_encode($data);

?>

And here’s part of the JavaScript:

ArticleAnimator.contentizeElement = function($el, d){
  $el.find('.big-image').css({ backgroundImage: "url(" + d.image + ")" });
  $el.find('h1.title').html(d.title);
  $el.find('.client').html(d.client);
  $el.find('.content .text').html(d.content);
  $el.find('.projet').html(d.projet);
}

Solution

  • Finally managed to get it working with the default kirby .htaccess

    <IfModule mod_rewrite.c>
    
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
    RewriteRule ^site/(.*) error [R=301,L]
    RewriteRule ^kirby/(.*) error [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php [L]
    
    </IfModule>