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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:03:32+00:00 2026-05-14T23:03:32+00:00

I’m trying to develop image crop using JQuery. I use ajax to upload the

  • 0

I’m trying to develop image crop using JQuery.
I use ajax to upload the image. after the image success fully uploaded. I load the uploaded image using jquery to its container.

$("#image_upload").html("<img src='" + data.path + "' width=\"460\" id=\"cropbox\" alt=\"cropbox\" />");

but the image selection doesnt work. why it could be happened ?
this is my code:

<style type="text/css">
    #preview {
        width: 150px;
        height: 150px;
        overflow: hidden;
    }
</style>
<script type="text/javascript" src="<?php echo base_url()?>asset/jqupload/js/ajaxfileupload.js">
</script>
<script type="text/javascript" src="<?php echo base_url()?>asset/jcrop/jquery.Jcrop.pack.js">
</script>
<link rel="stylesheet" href="<?php echo base_url()?>asset/jcrop/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
    function ajaxFileUpload(){
        $("#loading").ajaxStart(function(){

            $(this).show();
        }).ajaxComplete(function(){
            $(this).hide();
        });

        $.ajaxFileUpload({
            url: '<?php echo site_url()?>/upload/do_upload',
            secureuri: false,
            fileElementId: 'fileToUpload',
            dataType: 'json',
            success: function(data, status){
                if (typeof(data.error) != 'undefined') {
                    if (data.error != '') {
                        $("#image_upload").html(data.error);
                        $("#image_upload").fadeIn("slow");
                    }
                    else {
                        $("#image_upload").html("<img src='" + data.path + "' width=\"460\" id=\"cropbox\" alt=\"cropbox\" />");
                        $("#image_upload").fadeIn("slow");
                        $("#orig_h").val(data.width);
                        $("#orig_w").val(data.height);
                        //alert("<a href='" + data.path + "' />");
                    }
                }
            },
            error: function(data, status, e){
                $("#image_upload").html(e);
                $("#image_upload").fadeIn("slow");
            }
        })

        return false;
    }

    $(document).ready(function(){
        $(function(){
            $('#cropbox').Jcrop({
                aspectRatio: 1,
                setSelect: [0, 0, $("#oring_w").val(), $("#oring_h").val()],
                onSelect: updateCoords,
                onChange: updateCoords
            });
        });

        function updateCoords(c){
            showPreview(c);
            $("#x").val(c.x);
            $("#y").val(c.y);
            $("#w").val(c.w);
            $("#h").val(c.h);
        }

        function showPreview(coords){
            var rx = $("#oring_w").val() / coords.w;
            var ry = $("#oring_h").val() / coords.h;

            $("#preview img").css({
                width: Math.round(rx * $("#oring_w").val()) + 'px',
                height: Math.round(ry * $("#oring_h").val()) + 'px',
                marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                marginTop: '-' + Math.round(ry * coords.y) + 'px'
            });
        }
    });
</script>




<!-- begin main content -->
<div id="templatemo_content_area">
    <h1 class="content_title">Label Info<hr/></h1>
    <div id="templatemo_bi_full">
        <h2>Label Setting</h2>
        <div id="container">
        </div>
        <!--container-->
        <br/>
        <h2>Avatar</h2>
        <div class="info">
        </div>
        <div id="avatar_container">
            <form name="form" action="" method="POST" enctype="multipart/form-data">
                <ul>
                    <li class="leftHalf    ">
                        <label class="desc" for="lbl_type">
                            Change Your Avatar
                        </label>
                        <div>
                            <div id="avatar">
                                <img src="<?php echo $avatar?>" width="130" height="130" />
                            </div>
                            <div id="avatar_upload">
                                <input id="fileToUpload" name="fileToUpload" class="field field" value="" size="30" tabindex="5" type="file" /><input id="buttonUpload" name="buttonUpload" class="btTxt submit" type="submit" value="Upload" onclick="return ajaxFileUpload();"/><img id="loading" src="<?php echo base_url()?>asset/jqupload/images/loading.gif" style="display:none;">
                            </div>
                        </div>
                    </li>
                </ul>
                <ul id="crop_container">
                    <li class="leftHalf    ">
                        <label class="desc" for="lbl_name">
                            Avatar for crop
                        </label>
                        <div id="image_upload">
                            <img src="<?php echo $avatar?>" width="450" height="130" id="cropbox" name="cropbox" />
                        </div>
                    </li>
                    <li class="rightHalf     ">
                        <label class="desc" for="lbl_type">
                            Crop Display
                        </label>
                        <div id="preview">
                            <img src="<?php echo base_url() . 'files/' ?>" alt="thumb" />
                        </div>
                    </li>
                    <div class="info">
                    </div>
                    <li class="buttons ">
                        <input name="saveForm" class="btTxt submit" type="submit" value="Crop and Save" />
                    </li>
                </ul>
    <input type="text" id="x" name="x" />
    <input type="text" id="y" name="y" />
    <input type="text" id="w" name="w" />
    <input type="text" id="h" name="h" />
    <input type="text" id="oring_w" name="oring_w" />
    <input type="text" id="oring_h" name="oring_h" />
            </form>
        </div>
        <div class="cleaner">
        </div>
    </div>
    <div class="cleaner">
    </div>
</div>
<!-- end main content -->

Help me please ….

  • 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-14T23:03:33+00:00Added an answer on May 14, 2026 at 11:03 pm

    It doesn’t work because you get your image via ajax call. When you call the jcrop function on document.ready the image doesn’t exist. You need to put the jcrop code in the success function of the ajax call, after you add the image in DOM. Should be something like this (not tested):

        $.ajaxFileUpload({
                url: '<?php echo site_url()?>/upload/do_upload',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json',
                success: function(data, status){
                    if (typeof(data.error) != 'undefined') {
                        if (data.error != '') {
                            $("#image_upload").html(data.error);
                            $("#image_upload").fadeIn("slow");
                        }
                        else {
                            $("#image_upload").html("<img src='" + data.path + "' width=\"460\" id=\"cropbox\" alt=\"cropbox\" />");//it is important to add the jcrop code after this line
                            $("#image_upload").fadeIn("slow");
                            $("#orig_h").val(data.width);
                            $("#orig_w").val(data.height);
                            $('#cropbox').Jcrop({
                                aspectRatio: 1,
                                setSelect: [0, 0, $("#oring_w").val(), $("#oring_h").val()],
                                onSelect: updateCoords,
                                onChange: updateCoords
                });
    
                        }
                    }
                },
                error: function(data, status, e){
                    $("#image_upload").html(e);
                    $("#image_upload").fadeIn("slow");
                }
            })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 454k
  • Answers 454k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Old: (Bad) { "Grids": [ { "CommitImporterGrid": { "CostDivisionCode": "DL",… May 15, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer That is because your variable is called $achievementxml and not… May 15, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer If the grid shows or represents multiple orders at once,… May 15, 2026 at 9:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.