ajax -> "page not found"

Permalink
Hello,

i am experimenting with ajax to fill a div with content from an other php file after pressing a submit button. It works when i test this outside of C5 but when i apply the code into a single page i created my div is filled with a C5 "page not found" message.

Probably something small (lack of C5 knowledge) ?

thanks

Marco

stmarco
 
mdzoidberg replied on at Permalink Reply
mdzoidberg
Is this other php file a "single page"? there's two main way's to go about it. you can add another method to the page controller that'll handle your ajax services, which would be accessed with a URL generated like:

<?=View::url('mypage','my_ajax_method') ?>

... or you can add another file specifically for that purpose. if you want to go with the later, then create another folder in your package called tools, and a file within that called "services.php" or something. then you'd access that with a url that looks like:

(in your case this might be what you need)
<?=View::url('/packages/packagename/services/?') ?>
stmarco replied on at Permalink Reply
stmarco
Thanks for your reply,

the other page is not a single page it's just a php page that generates content that should be send back to my single page.

i've been trying to read some more about using ajax in C5 but i'm not getting very far.

for example i have no idea what <?=View::... you suggest means

could you point me to doc's that help me understand this

<div id="dCategorieen"><b>Categorieën...</b></div>
<?php
$form = Loader::helper('form');
print $form->submit('bCategorieen', 'Categorieën', array('onclick'=>'toonCategorieen()'))
?>


generates a button that activates javascript

<script type="text/javascript">
function toonCategorieen(categorieId)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {



btw i'm not building a package (or should i be)?

thanks

Gr

Marco
stmarco replied on at Permalink Reply
stmarco
Ok

i placed my php file that was supposed to give the feedback in a relative path, but the reference is made to the root, thats why my page returned a page not found

oeps

edit
it worked only with cID urls
edit

gr

Marco
stmarco replied on at Permalink Best Answer Reply
stmarco
Ok,

i'v started reading the developers doc from the start (learn to walk before you want to run)

on the cheat sheet i've stumbled on the solution to my problem.
when i paste this code in my xmlhttp.open code everything works.

<?php print DIR_REL; ?>



xmlhttp.open("GET","<?php print DIR_REL; ?>/single_pages/inc/getProductCategories3.php?categorieParent="+categorieId,true);


Probably will learn a lot more if i keep on reading

gr Marco