Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
PHP creating and calling AJAX files dynamically

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
grvulture
New one
New one


Joined: 30 May 2009
Posts: 1

PostPosted: Sat May 30, 2009 7:00 pm    Post subject: PHP creating and calling AJAX files dynamically Reply with quote

Hello. I have a problem calling the files I create dynamically I think...

In one page, I have a list of user activities. I want to make a comment box for each activity, where users can post their comments. Since the list is created dynamically from a database, all the divs, and also the JS files are created dynamically, by using this code:
Code:
    $commentid = $SQLdata->id;
    echo "Comments for activity #".$commentid." will go here...<br />";
    //load comments from database, if there are any comments in comments table associated with $commentid
  }
}
// ADD COMMENT SECTION
  createAJAX($commentid);
  echo '<script type="text/javascript" src="/components/com_cbactivity/add-on1/ajax'.$commentid.'.js"></script>'; ?>
    <div id="comments<?php echo $commentid; ?>"></div>
      <div>
      <input type="textarea" id="comment-name<?php echo $commentid; ?>" />
      <input type="hidden" id="comment-id" value="<?php echo $commentid; ?>" />
      <input type="submit" id="comment-submit<?php echo $commentid; ?>" value="Comment" />
    </div><?php 

This script calls function createAJAX. The function goes like this:
Code:
function createAJAX($id) {
$contents = 'Event.observe(\'comment-name'.$id.'\', \'keyup\', greet, false);

function greet(){
     var url = \'/components/com_cbactivity/add-on1/comments.php\';
     var pars = \'comment-name=\'+escape($F(\'comment-name'.$id.'\'));
     var target = \'comments'.$id.'\';
     var myAjax = new Ajax.Updater(target, url, {method: \'get\', parameters: pars});
}';

$file = '/components/com_cbactivity/add-on1/ajax'.$id.'.js';
$p = getcwd();
$fileHandle = fopen($p.$file, 'w'); //or echo ("can't open file<br />");
file_put_contents($p.$file, $contents);
fclose($fileHandle);

}

This function creates ajax files for every activity.(using prototype's Event.observe, which I know it works, tested the code statically) Here is a sample ajaxXXX.js file:
Code:
Event.observe('comment-name2077', 'keyup', greet, false);

function greet(){
     var url = '/components/com_cbactivity/add-on1/comments.php';
     var pars = 'comment-name='+escape($F('comment-name2077'));
     var target = 'comments2077';
     var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}

All the ajax files call comments.php file. Here it is:
Code:
<?php
  $new_comment = htmlspecialchars($_GET['comment-name']);
  echo "Comments go here...<br />";
  if ($new_comment!='') {
    echo "New Comment: $new_comment<br />";
  }
?>


But the AJAX linking doesn't work. User-input is not being processed...
I think the problem is the calling of the file through PHP:
Code:
  echo '<script type="text/javascript" src="/components/com_cbactivity/add-on1/ajax'.$commentid.'.js"></script>'; ?>

which is done in my very first code ( I hope you followed Smile ) however I might be missing something else...

please share your thoughts on this! Thank you!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert