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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:53:27+00:00 2026-05-18T09:53:27+00:00

I have the following ajax call: $(#welcome a.close).click(function(e) { $.ajax({ type: GET, url: /visitors/hide_welcome,

  • 0

I have the following ajax call:

$("#welcome a.close").click(function(e) {
    $.ajax({
        type: "GET",
        url: "/visitors/hide_welcome",
        success: function(){
            $("#welcome").hide(0);
            e.preventDefault();
        }
    });
});

Aimed at the following piece of my site:

<div id="welcome">
    <h2>Welcome  <a class="close" href="Javascript:;"></a></h2>
    <div class="left">
    </div>
    <div class="right">
        <div class="loginElement">

        </div>
    </div>
    <div class="clear"></div>
</div>

With the following code to answer the ajax request:

<?php
class VisitorsController extends AppController {

        function hide_welcome() {
                if($this->RequestHandler->isAjax()) {
                        $this->Session->write('Welcome.hidden', true);
                        echo 'Success.';
                }
                else {
                        echo 'I am, in fact, here.<br>';
                        $this->autoRender = false;
                }
        }

}
?>

It’s pretty straight forward. It calls to /visitors/hide_welcome to set a session variable noting that they’ve hidden the welcome. But it doesn’t seem to complete. If I place alerts on either side of it, like so:

$("#welcome a.close").click(function(e) {
    alert("Begin.");
            $.ajax({
        type: "GET",
        url: "/visitors/hide_welcome",
        success: function(){
            $("#welcome").hide(0);
            e.preventDefault();
        }
    });
            alert("End.");
});

They will trigger. But alerts placed in success are ignored. The same goes for error and complete. This was working just fine on my test machine. The page in question is definitely there, I can reach it with out ajax. Firebug reports nothing, neither does the error console. Success simply never fires.

The strangest part is that often if I reload manually the welcome disappears, indicating that the ajax call did fire. It just never returned. What is going on here? I’m at wits end. Any one see any trees I haven’t barked up yet?

SOLUTION:

CakePHP is supposed to auto detect ajax calls. But in this instance, it wasn’t. As a result it was running the code I had for the Ajax, but then returning a 404 when it failed to find a view. The solution was to append $this->autoRender= false; to the end of the ajax handling controller function. After that everything worked beautifully.

  • 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-18T09:53:28+00:00Added an answer on May 18, 2026 at 9:53 am

    I think given your symptoms, you’re redirecting to whatever URL the <a class="close"> you’re clicking on pointed to – since the default behavior isn’t prevented.

    The e.preventDefault() call should happen in the base method, not a callback, like this:

    $("#welcome a.close").click(function(e) {
        $.ajax({
            type: "GET",
            url: "/visitors/hide_welcome",
            success: function(){
                $("#welcome").hide(0);
            }
        });
        e.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery script: $(document).ready(function() { $.ajax({ url: 'temp.ajax.php', type: 'GET', success:
I have the following jQuery $.ajax({ type: GET, url: http://f.cl.ly/items/0i1V1L1k2F440L1m2Y0G/pointdata.xml, dataType: xml, success: parseXml
I have following ajax call: $(#container).html(loading...); $.ajax({ url: somedoc.php, type: POST, dataType: html, success:
I have the following code: $.ajax({ type: 'GET', url: 'index.php?route=checkout/onepagecheckout/getpaypaldata', dataType: 'json', success: function(json)
I have the following Ajax call: function ajaxCall(soap, url){ // Post SOAP request. $.ajax({
Possible Duplicate: jQuery: Return data after ajax call success I have the following function
I have the following AJAX call: $('#FonykerUsernameRegister').blur(function(){ if($(this).val().length > 2) { alert($(this).val()); $.ajax({ url:
I have the following jQuery Ajax call: $.ajax({ type: POST, url: addtobasket.php, data: sid=<?=
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I have the following working Ajax call - $.ajax({ url: ajaxUrl, type: sendHttpVerb, dataType:

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.