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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:49:10+00:00 2026-06-14T01:49:10+00:00

I have this ajax request which is being called whenever I change an input

  • 0

I have this ajax request which is being called whenever I change an input field:

$(document).ready(function(){
    $('#PostTitle').change(function(){
        var inputstring=$("#PostTitle").val();
        submitData(inputstring);
    });
});

function submitData(inputstring){
$.ajax({
        type: 'POST',
        url: '/myWebsite/posts/set_post_images',
        data: inputstring,
        dataType: "text",
        success:function(data){
            $("#selectImage").replaceWith($('#selectImage', $(data)));
        },
        error:function(){
            $('#selectImage').html("You failed misserably.");
        },
        timeout: 5000
    });
}

The above code is in the add.ctp file (a View for the Posts Controller). The called function set_post_images is in the Posts Controller itself and looks like this:

public function set_post_images($url = null) {
    if($url!=null){
        $this->set('imageArray', $this->getImages($url));
    } else {
        $this->set('imageArray', array("/img/someImage.png"));
    }
    if ($this->RequestHandler->isAjax()) {
         $this->autoRender = false;
         $this->layout = 'ajax';
         $this->render('/elements/selectImageElement');
    }
    return;
}

What I’m trying to do is to get the existing element from the selectImage div replaced by the new element. The problem is, ajax keeps returning the entire contents of the add.ctp file (the file from which the request is called).

What could be the cause of this and how can I fix it?

Edit: Solved

$this->Auth->allow(array(‘set_post_images’)); wasn’t set, so the response was returning the entire page. After fixing that the action could be spoken to.

Also, in the controller, the variable is not accessed via $url but via $this->data[‘url’].

Happy coding!

  • 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-14T01:49:12+00:00Added an answer on June 14, 2026 at 1:49 am

    $this->Auth->allow(array(‘set_post_images’)); wasn’t set, so the response was returning the entire page. After fixing that the action could be spoken to.

    Also, in the controller, the variable is not accessed via $url but via $this->data[‘url’].

    Happy coding!

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

Sidebar

Related Questions

I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have created a function which makes an ajax request to a PHP file
I have a form element which is being pulled in on request with ajax.
I have a function which makes an AJAX request to a server and returns
I have a input text which on keyup sends the ajax request and gives
I have an input field which a user can type into. This input also
I have this code for doing an ajax request to a webservice: var MyCode
So I have this javascript function, it sends an ajax requests to fetch a
Oh hai I have an ajax request, which works way: request starts: tinyMCE gets
I have a Div which I want to say Loading... while an AJAX request

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.