Hy every body, i am a new people in here, so i am need all of your help, please..

i have the script ajax like this,

<script type="text/javascript">
jQ(document).ready(function() {

     jQ().ajaxStart(function() {
         jQ('#loading').show();
         jQ('#result').hide();
    }).ajaxStop(function() {
         jQ('#loading').hide();
         jQ('#result').fadeIn('slow');
    });

     jQ('#frm').submit(function() {
     var formData = new FormData($(this)[0]);
        jQ.ajax({
            type: 'POST',
            url: jQ(this).attr('action'),
            data: jQ(this).serialize(),
            success: function(data) {
                jQ('#result').html(data);
            }
        })
        return false;
    });
})
</script>

That code is succes to upload the data to database except the file (image) whats should i do so the file image also uploaded to database?

i have try with this code,

$("form#data").submit(function(){

    var formData = new FormData($(this)[0]);

    $.ajax({
        url: window.location.pathname,
        type: 'POST',
        data: formData,
        async: false,
        success: function (data) {
            alert(data)
        },
        cache: false,
        contentType: false,
        processData: false
    });

    return false;
});

and both of data and file (Image) succes uploaded to database, but the animasi when uploaded to database is lost, what should i do so the data and file (image) inserted to database, but using animasi like my first code...

thanks, for your any help...

Member Avatar for LastMitch

and both of data and file (Image) succes uploaded to database, but the animasi when uploaded to database is lost, what should i do so the data and file (image) inserted to database, but using animasi like my first code...

The second code looks wrong. You can read and see how a ajaxSubmit to submit the form looks like and function:

http://malsup.com/jquery/form/#ajaxSubmit

To add to this, I would recommend against storing your images in a database. Rather store them in a folder and then just reference the location/filename in the database. It's much more efficient.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.