Jump to content

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 ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.