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

  • Home
  • SEARCH
  • 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 465939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:25:42+00:00 2026-05-12T23:25:42+00:00

I will explain more, because it might not be clear enough I want to

  • 0

I will explain more, because it might not be clear enough

I want to set the ajax url to: http://www.domain/controller/method
I already have everything in place for this with normal php.

But if I have to do this with ajax, I am not getting the intended result.
The result should be some json variable being echo’d back to me.
It is not entirely clear to me why.

In firebug I can see that the requestheader is not the same as the responseheader.
I see the layout view in the response. I do not know yet how to bypass that.
The basecontroller creates the view for the layout, but I have not extended the ajaxcontroller with the basecontroller??
For now I am running it threw another script that I call, but I would like it more if
I could do it by the first method.

Has anyone some suggestions, please ?

EDIT

It seems after the comments below I need to provide some logic to disable the layout?

first attempt:

class testController extends baseController implements IController
{

    public function testit()
    {
    $this->disableLayout = TRUE;
    $check='testit';
    $data =array();
    header('Content-type: application/json');

            $output = array(
            "check" => $check,
            "user" => $data
            );

            $this->content = json_encode($output);

            exit(0); // Stop script.

    }
}

thanks, Richard

  • 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-05-12T23:25:42+00:00Added an answer on May 12, 2026 at 11:25 pm

    I’m making a guess here, but I think you are trying to serve different content from same action depending how it was requested.

    To detect weather the page was requested by Ajax you could use specific header sent by browser.

    Usually most recent JavaScript libraries send

    X-Requested-With:XMLHttpRequest
    

    header together with their ajax request. If yours doesn’t you could easily make it to send it using something like this:

    //Just example using raw XMLHttpRequest
    var request = new XMLHttpRequest();     
    request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    //If you use Javascript library, see the documentation how to set custom request headers.
    //But as I said most modern libraries already send X-Requested-With
    

    Then in PHP you could check if request was made using Ajax by using this code block:

    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
               strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { 
       //Send JSON.
    } else {
       //Send HTML.
    }
    

    EDIT:
    As Elzo Valugi mentioned, don’t forget to use correct content type when outputing JSON in your action by using:

    header('Content-type: application/json');
    

    before sending any JSON or else you might have some problems with some JavaScript libraries.


    http://i47.tinypic.com/o5we91.jpg

    This is more or less how the request + response headers should look like. Note that I’m actually sending some unneeded ones here like Prototype version, etc.

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

Sidebar

Related Questions

This might be a little hard to explain, but I will try. I want
I will explain problem with an example: There is two table in my database,
Do you think x, y, z are good variable names? How will you explain
I will be teaching a class sson, and I need to explain what factors
Okay the question title may not have made sense... mostly because I don't know
I want to use a temp directory that will be unique to this build.
Can somebody explain to me why classes are not first class objects in Java?
Can anyone explain to me one or more efficient, reliable methods for opening a
Can anyone explain to me one or more efficient, reliable methods for opening a
I want to encapsulate requests to my android service because the service has the

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.