PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 14, 2022

[FIXED] Unable to load json via ajax with MAMP

 February 14, 2022     ajax, jquery, json, mamp     No comments   

Issue

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>


Answered By - Jolin M
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing