Ajax Package Help

Permalink
Hello All,

Im creating a package and i have the following structure, controllers->mypage.php, models->mypage.php and i have a single page called mypage.php that is using the on view function.

I can load content into mypage.php just fine from within the controller but what i need to do is load information into mypage.php single page using Ajax since is going to be refreshing every certain amount of time and I would prefer not to have to reload the whole page, can any body provide any ideas as to how to do this?

i will be using something like this within my single page

$("#divid").load("mypage.php");


would it be best to create a file under my package tools folder and call whatever i need from within that file? or is there a more elegant way?, any help is appreciated, thanks.

mdzoidberg
 
mdzoidberg replied on at Permalink Reply
mdzoidberg
Anyone?
Tony replied on at Permalink Best Answer Reply
Tony
umm, there's two main way's to go about it. you can add another method to the 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 latter, 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:

<?=View::url('/tools/packages/tony_popup/services/?') ?>

as far as the javascript goes, i normally use this kind of format:

$.ajax({ 
   type:'get',                 
   data:'mode=getPage&url='+encodeURIComponent(url)+'&showTitle='+parseInt(showTitle)+'&bID='+parseInt(this.bID)+'&area='+area+'&iframeMode='+iframeMode,
   url: this.servicesURL,
   success: function(response){ 
      //alert(response);
      eval('var jObj='+response);
      if( jObj && jObj.error ){
         tonyPopup.hide();
         alert(jObj.error);
      }else{   
         tonyPopup.pageWipeBox.find('.TonyPopup_boxBody').html( jObj.html ); 
         if(!jObj.iframeMode){
            tonyPopup.addHeaderCSS(jObj.cssFiles);
            tonyPopup.addHeaderJS(jObj.jsFiles);


hope that helps some.
mdzoidberg replied on at Permalink Reply
mdzoidberg
Thanks Tony, I will give this a try, thanks again for the help.
pvs replied on at Permalink Reply
pvs
Tony:
I'm in the same situation but i cannot get it to land on my script.

I created a package called properties, i do have a folder named tools and under it i have the php script name manage.
I used the following to access it:
php:
under dashboard/properties/manage
$theurltouse = View::url('tools/packages/properties/tools/manage/');


javascript:
showForm = function(actionToDo,urlToUse) {
   $.getJSON(urlToUse, {'action': actionToDo, 'ccm_token': CCM_SECURITY_TOKEN}, function(resp) {
      ccm_parseJSON(resp,function() {         alert("!");         alert(resp);         $("#showBox").html(resp);      $("#showBox").show();
      });
   });
}
Tony replied on at Permalink Reply
Tony
don't think you need the second /tools in the url
ryan replied on at Permalink Reply
ryan
I found this thread & thought I'd post the function to get the package tools url:

$url = Loader::helper('concrete/urls');
$tools_url = $url->getToolsURL('tools_page','your_package_handle');


reference your tools_page without the ".php" on the end
mdzoidberg replied on at Permalink Reply
mdzoidberg
Thanks ryan, good info.