Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I used a tutorial to get the following ajax code. In the tutorial, they have the library jquery.form.js. Here is the code:
JavaScript
function onsuccess(response,status){
    $("#onsuccessmsg").html(response);
        alert(response);
    }
    $("#uploadform").on('change',function(){
        var options={
        url     : $(this).attr("action"),
        success : onsuccess
    };
    $(this).ajaxSubmit(options);
        return false;
});

What if I don't want to have jquery.form.js implemented. What would be the equivalent code with normal ajax (without the library)?
Posted

1 solution

This code looks like a form-submission and callback after that.
Yeah, you can do it without using that library.
JavaScript
$("#yourForm").submit(function() {
    $.ajax({
        url: $(this).attr("action"),
        data: $(this).serialize(),
        cache: false,
        success: function(response){
            $("#onsuccessmsg").html(response);
        },
        error: function(xhr){
            $("#onsuccessmsg").html(xhr.responseText);
        }
    });
});


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900