I threw together an image cropping thing,
(modified as best I could cause the image is already on the server)
If, you can, select an image and submit the form, you are then taken to the cropping part.
you can crop the image fine, but when that box pops up asking you if you want to save the image, it doesn’t work and cant figure out where the problem is, best I can figure is that the problem lies in ajax_image.php as your taken to that page once its confirmed you want to save the image.

Can you see the problem?

Well your success callback looks like this:

  $("#thumbs").html("<img src='../providers/images/1/"+rsponse+"' />");

But I don’t see any elements corresponding to those IDs on the page.

Also, try adding:


to the top of the function and post the results back here.

ok took look at the sample and noticed to have an empty div with the id=“thumbs”. So I guess thats where the new cropped image appears. (So I added one)
I put that code at the beginning of that function

                                    $("#thumbs").html("<img src='<?=$dirname?>"+rsponse+"' />");

opened up the console via firebug and heres the screen shot

Does this help?

I dont understand what #cropimage.hide() does and why its even needed



This is what the ajax part of your script is doing:

When the cropping ends and the user confirms they want to save the image, it is firing off a GET request to the file ajax_image.php, passing it a load of parameters in a query string.


The complete address looks like (taken from Chrome console):

It’s turning off caching for this particular request.


Then it’s specifying a success callback that will be executed if the AJAX request is successful (which it is, as you can tell by the 200 response code)

  $("#thumbs").html("<img src='../providers/images/1/"+rsponse+"' />");

This callback takes one parameter, which is the server’s response.

This appears to be a string, containing the name of a file: feature.jpg

It then hides the element with the id of “cropimage” and empties the element with the id “thumbs”.
After that it creates an <img> tag, setting its src attribute to a path relative to your script, concatenated with the server’s response (e.g. ‘…/providers/images/1/feature.jpg’)
It then inserts this image tag into the element into the element with the id of “thumbs”

It seems at this point that your JavaScript is doing what is expected and that the problem lies with your PHP script which should be saving a cropped image on your file system, but isn’t.

ok, thanks…
so itsa off to the php forum then?:
thanks for the explanation though, I really was lost on what that code meant

No probs.

This would be the place I would look next (the PHP script).

However, feel free to post back here if it turns out to be a JS issue after all, as AJAX really isn’t that mysterious, especially when you’ve got jQuery providing you with a nice cross browser syntax :slight_smile:

oh, I just noticed something,this is the complete address (taken from chrome)

I see a problem is the the img is undefined

shouldn’t it not?

Yeah, I noticed that too.
It all really depends what your PHP script is expecting.

The img parameter is defined thus:


Which is simply the value of the element with the id of “image_name”.
This element doesn’t appear to be present on your page, hence it is being passed as undefined.

I think I may have figured something, if the URL is

and this is the bit the generates it


can I get the image name similar to how I got the thumb_width?

var thumb_width = obj.width;

Something like
var image_name =;
then rewrite the url thing like


what do you think?

Sounds like a plan :slight_smile:

You can also do console.log(obj); and examine which properties it has.

dannngg, this is the result of the


which seem to be the properties of the crop, and need to get the name of the image to crop, that must be a job for PHP though but it sure would be nice if I could grab that name via jguery or ajax though

I think I found something out, I changed that url thing to


and the URL then became
So the img is now correct
But the image now is being saved as a 300x300 black square, so I quess the only problem now is the image crop part which is all PHP

$t_width = 300;    // Maximum thumbnail width
$t_height = 300;    // Maximum thumbnail height
$new_name = "feature.jpg"; // Thumbnail image name
$path = "../providers/images/{$_GET['id']}/";

if(isset($_GET['t']) and $_GET['t'] == "ajax")
        $ratio = ($t_width/$w); 
        $nw = ceil($w * $ratio);
        $nh = ceil($h * $ratio);
        $nimg = imagecreatetruecolor($nw,$nh);
        $im_src = imagecreatefromjpeg($path.$img);
        echo $new_name;

Thanks soo much for your help, now its to try and figure whats wrong with thhe bit of PHP which saves the image.