Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
providing pictures
Source Link
E.A.T
  • 384
  • 2
  • 16

I created a custom path via hook_menu with a page callback to a function that prints json.

It all works in the sense that requesting: http://cms.tripchi.com/tripchi/getme returns my JSON, but the header says it's 404 which is throwing off everything in the app. This only returns the 404 status on the client's godaddy server (PHP Version 5.4.19 w/ CGI/FastCGI), but returns 200/Ok on my local PHP Version 5.3.5 w/ Apache 2.0 Handler. All Drupal configurations and databases are equal.

hook_menu

function tripchi_menu() {
    return array(
        'tripchi/getme' => array(
            'title' => 'My Profile',
            'description' => 'mobile test for user status and object',
            'access callback' => 'user_access',
            'access arguments' => array('access content'),
            'page callback' => 'tripchi_getme')
    );
}

callback function

function tripchi_getme(){
    $user = $GLOBALS['user'];
    $json = array();
    // ... a bunch of stuff to construct a special array;
    drupal_add_http_header('Status', 'Ok');
    drupal_add_http_header('Access-Control-Allow-Origin', '*');
    http_response_code(200);
    //echo json_encode($json);
    drupal_json_output($json);
    drupal_exit();
    //die();
    // i've tried all combinations of commenting/uncomming the above...
}

below screenshot of the requests locally (right) and remotely (left): below screenshot of the requests locally (right) and remotely (left)

why does this always return 404 but also give me my perfectly json encoded data?

I created a custom path via hook_menu with a page callback to a function that prints json.

It all works in the sense that requesting: http://cms.tripchi.com/tripchi/getme returns my JSON, but the header says it's 404 which is throwing off everything in the app. This only returns the 404 status on the client's godaddy server (PHP Version 5.4.19 w/ CGI/FastCGI), but returns 200/Ok on my local PHP Version 5.3.5 w/ Apache 2.0 Handler. All Drupal configurations and databases are equal.

hook_menu

function tripchi_menu() {
    return array(
        'tripchi/getme' => array(
            'title' => 'My Profile',
            'description' => 'mobile test for user status and object',
            'access callback' => 'user_access',
            'access arguments' => array('access content'),
            'page callback' => 'tripchi_getme')
    );
}

callback function

function tripchi_getme(){
    $user = $GLOBALS['user'];
    $json = array();
    // ... a bunch of stuff to construct a special array;
    drupal_add_http_header('Status', 'Ok');
    drupal_add_http_header('Access-Control-Allow-Origin', '*');
    http_response_code(200);
    //echo json_encode($json);
    drupal_json_output($json);
    drupal_exit();
    //die();
    // i've tried all combinations of commenting/uncomming the above...
}

why does this always return 404 but also give me my perfectly json encoded data?

I created a custom path via hook_menu with a page callback to a function that prints json.

It all works in the sense that requesting: http://cms.tripchi.com/tripchi/getme returns my JSON, but the header says it's 404 which is throwing off everything in the app. This only returns the 404 status on the client's godaddy server (PHP Version 5.4.19 w/ CGI/FastCGI), but returns 200/Ok on my local PHP Version 5.3.5 w/ Apache 2.0 Handler. All Drupal configurations and databases are equal.

hook_menu

function tripchi_menu() {
    return array(
        'tripchi/getme' => array(
            'title' => 'My Profile',
            'description' => 'mobile test for user status and object',
            'access callback' => 'user_access',
            'access arguments' => array('access content'),
            'page callback' => 'tripchi_getme')
    );
}

callback function

function tripchi_getme(){
    $user = $GLOBALS['user'];
    $json = array();
    // ... a bunch of stuff to construct a special array;
    drupal_add_http_header('Status', 'Ok');
    drupal_add_http_header('Access-Control-Allow-Origin', '*');
    http_response_code(200);
    //echo json_encode($json);
    drupal_json_output($json);
    drupal_exit();
    //die();
    // i've tried all combinations of commenting/uncomming the above...
}

below screenshot of the requests locally (right) and remotely (left): below screenshot of the requests locally (right) and remotely (left)

why does this always return 404 but also give me my perfectly json encoded data?

seemingly significant difference in comparing servers
Source Link
E.A.T
  • 384
  • 2
  • 16
Loading
pointing out it says 200 locally and better title
Source Link
E.A.T
  • 384
  • 2
  • 16
Loading
Source Link
E.A.T
  • 384
  • 2
  • 16
Loading