0

I have a form that is submitted via jquery for an instant image upload. When the image starts to upload via the form, i show a cancel upload button via jquery. Now is there a way using jquery, i can stop/cancel the form submission on the click property of the cancel upload button? What i do currently is that i delete the current upload from the databse using ajax and then refresh the page. this will not upload the image but i am trying to find something that will not let the page refresh.

$('.deleteimage').live("click", function () {
    var ID = $(this).attr("id");
    var IPString = $(".ipvaluetable").val();
    var dataString = 'msg_id=' + IPString;
    document.getElementById("preview").style.visibility = "hidden";
    $(".preview").slideUp('slow', function () {
        $(this).remove();
    });
    document.getElementById("deleteimage").style.visibility = "hidden";

    $.ajax({
        type: "POST",
        url: "http://schoolspam.com/delete_image.php",
        data: dataString,
        cache: false,
        success: function (html) {}
    });

    location.reload();

    return false;
});
Steve Papa
  • 422
  • 2
  • 9

2 Answers2

1

Well on cancel you can do event.preventDefault(); and then return false.

Example

$('.cancel').on('click', function(e){
   e.preventDefault();
   return false;
});
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0

Please use below code and also see my comments :

$('.deleteimage').live("click", function (e) {

    e.preventDefault();//Stops default behaviour

    var ID = $(this).attr("id");
    var IPString = $(".ipvaluetable").val();
    var dataString = 'msg_id=' + IPString;
    document.getElementById("preview").style.visibility = "hidden";
    $(".preview").slideUp('slow', function () {
        $(this).remove();
    });
    document.getElementById("deleteimage").style.visibility = "hidden";

    $.ajax({
        type: "POST",
        url: "http://schoolspam.com/delete_image.php",
        data: dataString,
        cache: false,
        success: function (html) {}
    });

    //location.reload();//This one needs to be removed so as to stop the reload

    return false;
});
Roy M J
  • 6,926
  • 7
  • 51
  • 78