0

I am using the following ajax code to get the result form another one php, now I need to append the result to the appropriate div(preview) id

$("#imageform").ajaxForm({
    target: '#preview'
}).submit();
algorhythm
  • 8,530
  • 3
  • 35
  • 47
askm3
  • 59
  • 4
  • 15
  • possible duplicate of [How to return the response from an Ajax call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Bud Damyanov Oct 27 '14 at 08:22

2 Answers2

0

If you are using jQuery Form Plugin, Use like this..data is the data which you are sending from php file.

$("#imageform").ajaxForm({
            clearForm: 'true',
            success: function(data){
            if(data != '')
            {
                $("#preview" ).append(data);
            }
            }
        }).submit();
Choco
  • 1,054
  • 1
  • 7
  • 20
0

Use the success callback function and don't specify the target option.

$("#imageform").ajaxForm({
    success: function(d,s,x){
       $("#preview").append(d);
    }
}).submit();

The problem is that the target option is used to "replace" the target (or contents of the target) along with the replaceTarget option. But since what you need to "append" instead of "replace", you should avoid the whole target/ replaceTarget mechanism

Leo
  • 14,625
  • 2
  • 37
  • 55