2012-11-07 12 views
0

我使用jquery.form.js到AJAX提交表單並獲取響應更新成功圖片src。如何使用jquery.form.js

我的PHP頁面被設置爲回波圖像的URL像 「圖像/拇指/ 071112130957.jpg」

繼承人我的jquery:

$("#imageform").ajaxForm(
{ 
target: '#preview' 
}).submit(); 
}); 

我的繼承人HTML表單

<form action="cropscript.php" id="imageform" method="post" enctype="multipart/form-data"> 
<input type="file" name="image" id="image" /> <br/> 
<input type="submit" name="submit" value="upload image" /> 
</form> 

<div id="preview" > </div> 
<img src = "thumbs/default.jpg" id="thumb_img" /> 

現在我的問題是如何在ajaxform成功後更新img#thumb_img src?

回答

1

這是什麼爲我工作。

$(document).ready(function() { 
    $('#image').live('change', function() 
    { 
      $("#imageform").ajaxForm({ 
        target: '#preview', 
        dataType: 'json', 
        success : function (response) { 
           $('#thumb_img').attr('src','images/thumbs/'+response.imgsrc); 
        } 
      }).submit(); 

    }); 
}); 
2

我使用ajaxFrom很久以前的事,但它只是在我的頭上彈出
請與您的版本檢查文檔

$('#imageform').ajaxForm({ 
    target : '#preview', 
    complete : function (response) { 
    $('#thumb_img').attr('src', response.imgsrc); 
    } 
}); 

可以測試我,如果不工作讓我知道

+0

它不工作。我如何生成response.imgsrc?我做了數據類型:json和echo json_encode($ imgsrc),是嗎? – jinni

+0

我的JSON是outputing:{ 「IMGSRC」: 「071112161921.jpg」}如何使用jQuery怎麼做呢? – jinni

+0

如果數據是JSON,您可以使用,如果沒有把握控制檯日誌響應數據 $( '#thumb_img')ATTR( 'SRC', '文件夾/路徑/' + response.imgsrc)。 – Kotzilla