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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:06:37+00:00 2026-06-18T09:06:37+00:00

What I want, is when a button is clicked, it calls the .ajax request

  • 0

What I want, is when a button is clicked, it calls the .ajax request to pass a three variables through the url to the actions, to update the database with a changed image src string.

I cannot seem to get the .ajax request to execute successfully. I am getting the error alert I setup.

Here is the jquery that executes the ajax

    //click through multiple thumbs
        $(".prev").click(function() {
            $(this).parent().find(".thumb-container").find("div:last").insertBefore($(this).parent().find(".thumb-container").find("div:first"));
            $(this).parent().find(".thumb-container").find(".thumb").removeClass("selected");
            $(this).parent().find(".thumb-container").find("div:first").addClass("selected");
                var selectedImage = $(this).parent().find(".thumb-container").find(".selected").find("img").attr("src");
                var quiltPatchId  = $(this).parent().parent().parent().parent().attr("id");
                var CalendarOfEventsID = <?php print $CalendarOfEventsID        ?>;
                var briefsPatchId;
                //update image to uploadedImage field
                 $.ajax({
                    url: "/cms.php/calendar-of-events/"+CalendarOfEventsID+"/entries/update-image/"+quiltPatchId+"/"+selectedImage,
                    dataType: "json",
                    success: function(data){
                        briefsPatchId   =   data.briefsPatchId;
                    },
                    error: function(jqXHR, textStatus, errorThrown){
                        alert("Oops!  That image was not successfully updated.");
                    }
                 });

        })

So the ajax should call the url with variables into the routing.yml here:

calendar_update_image:
  url: /calendar-of-events/:id/entries/update-image/:quiltPatchId/:selectedImage
  param: { module: calendar_of_events, action: updateImage }

which then calls the actions.class:

//update selected image
    public function executeUpdateImage(sfWebRequest $request){
        $briefsId     = $request->getParameter('id');
        $quiltPatchId = $request->getParameter('quiltPatchId');
        $selectedImage = $request->getParameter('selectedImage');

        $briefsPatch = Doctrine::getTable('CalendarOfEventsEntries')->find($quiltPatchId);

        $briefsPatch['uploadedImage'] = $selectedImage;
        $briefsPatch->save();
        $this->briefsPatchId    =   $briefsPatch['id'];
    }

Then I can pass some data back to the template updateImageSuccess.php

<?php
/*
* This page is only called via ajax, so no templating necessary; uses blank template
*/
$data = array('briefsPatchId' => $briefsPatchId);
echo json_encode($data);    
?>

I have this working in another template, using drag and drop, so I am thinking maybe I am just missing something small. Is there a way to debug the ajax call to see where it is failing?

UPDATE:

The main issue was with the symfony cache. Once cleared, it could id the page url. The problem now is getting the image string through the url successfully. I have encoded it using

selectedImage = encodeURIComponent(selectedImage);

which fixes the “/”‘s but the extension is throwing off the url. This may require starting a new question. If so, let me know.

UPDATE

OK, I have gotten it to work, by splitting and popping the image so it passes successfully through the url. I would think there is a better way to do this, so please let em kow if this is an ill approach.

This is what works now:

var selectedImage = $(this).parent().find(".thumb-container").find(".selected").find("img").attr("src");

            var selectedImage = selectedImage.split('.');
            var imagePath = selectedImage[0];
            var imagePath = selectedImage[0].split("/").pop();
            var imageExt = selectedImage[1];

So I take the image string, pull out the extension into another var, then split.pop the image string location to remove all previous folders.

What I had originally was uploads/images/my_image.jpg, which is now split into two vars, which are imagePath = my_image and imageExt = jpg, then I passed the two vars through the url

url: "/cms_dev.php/calendar-of-events/"+CalendarOfEventsID+"/entries/update-image/"+quiltPatchId+"/"+imagePath+"/"+imageExt,

and picked them up and put them back together in the actions.

  • 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-18T09:06:38+00:00Added an answer on June 18, 2026 at 9:06 am

    I won’t give you an answer, but I will describe how I will debug it:

    • just before calling $.ajax, put an alert to check if the url is ok

      alert("/cms.php/calendar-of-events/"+CalendarOfEventsID+"/entries/update-image/"+quiltPatchId+"/"+selectedImage)
      
    • if the url seems to you, put some var_dump inside executeUpdateImage to see if params are ok:

      public function executeUpdateImage(sfWebRequest $request) {
        $briefsId      = $request->getParameter('id');
        $quiltPatchId  = $request->getParameter('quiltPatchId');
        $selectedImage = $request->getParameter('selectedImage');
      
        var_dump($briefsId);
        var_dump($quiltPatchId);
        var_dump($selectedImage);
        die();
      
    • then check that $quiltPatchId exists in your database
    • var_dump the result of saving into the database:

      $result = $briefsPatch->save();
      var_dump($result);
      die();
      
    • finally, check the error message inside your javascript and test it in dev mode (frontend_dev.php for example):

      error: function(jqXHR, textStatus, errorThrown){
          alert("Oops!:"+textStatus);
      }
      

    With all these information, you will be able to find what’s wrong. Otherwise, come back with result about debugging.

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

Sidebar

Related Questions

I want to create a button which when clicked calls an action. I have
I want to create updated URL when Next 1000 button is clicked on the
When a button/link is clicked, I want this URL to be called followed by
when a submit button is clicked i want to generate a pop up showing
Button onTouchLitsener does not change when clicked. I want the button to change when
I want to appear another view in MainView when i clicked button like following
I want the submit button to disappear after it's clicked and a new layer
I want to bring the cursor to a textbox when i clicked a button.
In my Delphi Project i want to have a 'Settings' button that when clicked,
So I want a Button1 to be clicked when the submit button has been

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.