Jump to content

Reusable code in include_once and AJAX ?


nEJC

Recommended Posts

I want to do a bunch of code snippets where I could get the same information no matter if it was executed from included code or called with AJAX.

 

Let me put out my idea - I'd love to hear your comments.

I hope this proto code is understandable  ;D

function get_data( $isAJAX, $param1, $param2 ) {
  do the magic to get $data
  if( $isAJAX )
    echo ajax wrapped $data
  else
    echo $data
}

if( !defined('TOP') ) {
  we have ajax call, parse $GET
  get_data( TRUE, $1, $2 )
}

 

If code would be used with include all I'd have to do is call the same function with first parameter as FALSE.

 

What do you think?

 

Link to comment
https://forums.phpfreaks.com/topic/117877-reusable-code-in-include_once-and-ajax/
Share on other sites

I'm not quite sure what the code is for. Also, for a function called get*() I'd expect it to return data, not output it.

 

If code would be used with include all I'd have to do is call the same function with first parameter as FALSE.

 

I don't understand what you mean. All include() (and require()) does is that it starts evaluating another file at the point where the call to include() is.

 

I hope this proto code is understandable  ;D

 

You usually call such code pseudocode. Just saying ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.