I have a problem in my code, a button calls this ajax request from within a jQuery UI dialog
myaudioupload = $.ajax({
url: "some url",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (data) {
var data = jQuery.parseJSON(data);
console.log('json parsed');
if(data.status==1){
console.log('status ok');
}
else{
console.log('status not ok');
}
}
});
If the user wants to cancel the request, user closes the dialog box and then the following lines are executed:
close: function(event, ui) {
if(myaudioupload.abort()) {
console.log('aborted');
$('#uploadaudioform')[0].reset();
}}
This works fine only when the data is being uploaded, not after the upload succeeds or before the upload is triggred. In these conditions, this message shows up
Uncaught TypeError: Cannot call method ‘abort’ of undefined
I have even tried these ways while aborting:
if(myaudioupload!=='undefined' && myaudioupload.abort=='function'){
myaudioupload.abort();
console.log('aborted');
$('#uploadaudioform')[0].reset();
}
but this also does not work; the same error occurs.
So please help me how should i do this or if something is wrong in my code.
Thanks.
I think
myaudioupload.abort=='function'is not a correct way to check property type, use