Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:22:29+00:00 2026-06-02T18:22:29+00:00

What is the best way to load async data in Drupal 7? Curriently I’m

  • 0

What is the best way to load async data in Drupal 7?

Curriently I’m loading my data with jQuery with my own nodes. I have build an own menu_hook which is aviable under /events and e.g. /events/2012-04-17 this page is also aviable for normal browsing. I check if $_SERVER['HTTP_X_REQUESTED_WITH'] is set if it is I return the data in a JSON string and parse the data.

Can I run in some trouble if I activate some caching technics? Or is there a better way to load the data? It seems that this does not work with boost because I’m killing the script with die() what could I do else?

function my_module_menu() {
    $items['events'] = array(
        'page callback' => 'event_page',
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
    );
    $items['events/%date'] = array(
        'page callback' => 'event_page',
        'page arguments' => array(2),
        'access callback' => TRUE,
        'type' => MENU_VISIBLE_IN_BREADCRUMB,
    );
    return $items;
}

function event_page($date=null) {
    $build=array();
    // add some other "controls"
    $build['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
    );

    if((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) || strpos($_SERVER['REQUEST_URI'], '?json')!==FALSE) {
        header('Cache-Control: no-cache, must-revalidate');
        header('Content-type: application/json', true);
        $json=loadData();
        die(json_encode($json));
    }

    return $build;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:22:30+00:00Added an answer on June 2, 2026 at 6:22 pm

    You can use drupal_json_output instead, this will automatically change the headers so no exit() is required.

    Another option would be to change the delivery callback on that particular path combined with the data from $_SERVER using hook_page_delivery_callback and then return a valid array for the page using ajax_command‘s.

    The first option is alot easier, I’ve never tried the second one myself but it might be too much for your situation. Unfortunately I don’t know how either of these techniques behaves together with boost but hopefully one of them will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Best way to load seed data? I have an Author table that is tightly
I have been wondering which is the best way to load a navigation view.
What's the best way to load HTML markup for a custom jQuery UI widget?
What is the best way to load static data files containing game level maps
What is the best way to load huge text file data in delphi? Is
What is the best way to load seed (initial or test) data into grails
I wonder how's the best way to load sound files in Game? loading from
I’m trying to decide the best way to load data into my app, it’s
What is the best way to load external data in android? Currently, this is
Using jquery what is the best way to load a snippet of code for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.