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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:41:44+00:00 2026-05-23T10:41:44+00:00

My problem is somewhat similar to cakephp, jquery, .ajax(), dataType: json , but my

  • 0

My problem is somewhat similar to cakephp, jquery, .ajax(), dataType: json, but my observations are little different.

I am working on a Cake PHP project. Consider a group_assoc submodule of opstools module. So, there is this function group_assoc() inside opstools_controller.php which is invoked by an ajax call to update group associations.

My ajax post is like this –

$.post( url,
function(data) 
{
   if(data)
   {

      alert(data.success);  //alerts -> undefined
      alert(data);          //alerts -> {"success":true}  or {"success":false}

      if(data.success)
      {
         //does not work
      }
  }

}, "json");

And inside the opstools_controller.php I have –

function group_assoc()
{
     ...
     ...
     //some code
     ...
     ...
     $success //contains true or false - depending on previous logic

     echo json_encode(array("success" => $success));
}

So, inside the Ajax response handler function (in the ajax posting part), I am getting a string like {"success":false}.

How do I fix this problem. I remember using similar Ajax posting and responding using json_encode, which worked perfectly fine in a previous project with Core PHP (no Cake PHP). What could be the problem here? Any pointers?

Update
Do I need to explicitly set any header? Why would that be needed? Where to check if it is set that we are returning text. I tried putting header("HTTP/1.1 200 OK"); before the echoing part, as is done in the existing code – similar Ajax handler functions.

Also, I have set $this->autoRender = false; in my module.

  • 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-23T10:41:45+00:00Added an answer on May 23, 2026 at 10:41 am

    It looks to me like you might be missing an argument to the $.post() API:

    .post( url, [data,] [success(data, textStatus, jqXHR),] [dataType] )
    

    Specifically, the data argument. The API’s example seems to indicate that it’s smart enough to figure out when it’s missing (the argument doesn’t appear in the API example), but it may be worth adding it explicitly:

    $.post( url, null,
      function(data) 
      {
        if(data)
        {
    
           alert(data.success);  //alerts -> undefined
           alert(data);          //alerts -> {"success":true}  or {"success":false}
    
        if(data.success)
        {
          //does not work
        }
      }
    
    }, "json");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll rewrite a different question of mine, because the problem case somewhat changed: If
I am somewhat new to jQuery and I have a problem with something I
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I have a query that UNION 's two somewhat similar datasets, but they both
The title might be somewhat ambiguous, but bear with me (The only similar question
I am working on a prototype for a project that is somewhat similar to
I'm wondering if this is something somewhat simple, but I'm having a problem ONLY
My problem is somewhat similar to this problem Custom Validation on group of checkboxes
Somewhat similar to Stack Overflow question Compose and andThen methods , I've been working
This issue is somewhat related: Problem with Code Generated by XSD.EXE: Sequence of Elements

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.