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 8359659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:13:03+00:00 2026-06-09T11:13:03+00:00

I have an Ajax request that sends some data to a page and expects

  • 0

I have an Ajax request that sends some data to a page and expects back a truthy or falsey value depending on if the data was saved. In my controller I do everything and set the content to a true or false value. I really don’t want to create a view just to output 1 variable, so I was wondering if there was a way that I don’t have to use a view and only use the controller to output simple strings.

  • 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-09T11:13:06+00:00Added an answer on June 9, 2026 at 11:13 am

    I believe you cannot disable views completely, but there’s a pretty simple workaround: you can create one view and use it for many actions.

    Let’s say we’ve created the view views/main/ajax.cfm, what could be inside it? Obviously, simplest way is:

    <cfoutput>#HTMLEditFormat(rc.response)#</cfoutput>
    

    Personally I like returning JSON, it allows me to have status field, plus data, if needed. This way my view looks like this:

    <cfheader name="Content-Type" value="application/json" />
    <cfoutput>#SerializeJSON(rc.response)#</cfoutput>
    

    Any way, now in our action we need to do something like this:

    // prevent displaying the layout
    request.layout = false;
    
    // force special view
    variables.fw.setView("main.ajax");
    
    // init response (according to the choice made earlier)
    rc.response["status"] = "OK";
    rc.response = "";
    

    There’s one more gotcha for this. Sometimes you don’t want AJAX page to be accessed directly (like opened in browser), or vise-versa — want to do some debugging when it is.

    There’s a cool helper isAjax in CFWheels framework, it is easy to port to the FW/1. It could be as simple as adding method like this to controller:

    /*
    * Check if request is performed via AJAX
    */
    private boolean function isAjax() {
    
        return (cgi.HTTP_X_REQUESTED_WITH EQ "XMLHTTPRequest");
    
    }
    

    Actually, that setup code above is also helper method in my apps:

    /*
    * Set up for AJAX response
    */
    private struct function setAjax() {
    
        // prevent displaying the layout
        request.layout = false;
    
        // force special view
        variables.fw.setView("main.ajax");
    
        local.response["status"] = "OK";
    
        return local.response;
    
    }
    

    So in my action code whole check looks like this, which is pretty compact and convenient:

    if (isAjax()) {
        rc.response = setAjax();
    }
    else {
        return showNotFound();
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have a tooltip on an anchor element, that sends an AJAX request on
I have an Ajax request that can return more than one valid value, so
I have a AJAX request that will return a string that contains some HTML
I have a form on a page that sends data to php file via
Alright, so I have some jQuery code that will send an AJAX request to
I have a simple AJAX request which sends data to a PHP and the
So I have some javascript code that sends data to my controller: Javascript: <script
I have the following in a ColdFusion page that pulls in some data for
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
I have an app that sends multiple Ajax requests simultaneously. I was originally running

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.