SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reload image after upload!?

    I'm trying to create an upload script and got that. Its a profile image upload script so everytime a user chnages the profile image the name will still be the same: userid.jpg.

    Is there a way to refresh my image if success...
    Code JavaScript:
    if (success == 1){
       result = '<span class="msg">Image uploaded...<\/span><br/><br/>';
       // Something here to tell my image to refresh? //
    }

    My image:
    Code HTML4Strict:
    <img src="images/userid.jpg">

    Hope this is understandable...

    Thanks in advance...

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I assume your using PHP to manage the upload so what you need to do is use something like a JSON array when returning the data back to the JS function and set the new image path within that. For example...

    Javascript
    Code JavaScript:
    $.ajax({
        success: function(data) {
            if (data.status) {
                result = '<span class="msg">Image uploaded...<\/span><br/><br/>';
     
                if (data['image'].length > 0) {
                    $('#img_id').attr('src', data.image);
                }
            } else {
                alert('Error!');
            }
        }
    });

    PHP
    PHP Code:
    echo json_encode(array(
        
    'status' => true// true = no errors | false = errors
        
    'image'  => $newImageURL
    )); 

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SgtLegend View Post
    I assume your using PHP to manage the upload so what you need to do is use something like a JSON array when returning the data back to the JS function and set the new image path within that. For example...

    Javascript
    Code JavaScript:
    $.ajax({
        success: function(data) {
            if (data.status) {
                result = '<span class="msg">Image uploaded...<\/span><br/><br/>';
     
                if (data['image'].length > 0) {
                    $('#img_id').attr('src', data.image);
                }
            } else {
                alert('Error!');
            }
        }
    });

    PHP
    PHP Code:
    echo json_encode(array(
        
    'status' => true// true = no errors | false = errors
        
    'image'  => $newImageURL
    )); 
    And yes... Thanks... Did the job ;-)

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No problem


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •