Reputation: 381
I am working on php files. I created ajax jquery function to handle delete and display uploaded file. When i want to delete files event.preventdefault() function not working in firefox but it working fine in chrome browser. How can i solve this.
/* Read Upload Files */
function readuploadfiles(jrsid){
var jourid = jrsid;
//console.log("Journal Id: "+jourid);
//var evt = e || window.event;
//evt.preventDefault();
$.get("readuploadfiles.php", {jid: jourid}, function (data) {
//alert("Data: " + data + "\nStatus: " + status);
console.log(data);
$('#uploadfiles').html(data);
});
return false;
}
/* Delete upload file */
function deleteuploadfiles(id){
var conf = confirm("Are you sure, do you really want to delete file?");
if (conf == true) {
event.preventDefault();
$.post("deleteuploadfile.php", {id: id}, function (data) {
console.log(data);
readuploadfiles(data);
}
);
return false;
}
}
Upvotes: 0
Views: 50
Reputation: 323
The preventDefault
method is only accessible if you have access to the event object that is passed in to your method when an event is triggered. Meaning, in order for event.preventDefault()
to work, you'll first need to accept the event
object in your method. You'll need something like this:
function deleteuploadfiles(event, id){
// Now you can use the event object
event.preventDefault();
}
Hope that helps.
Upvotes: 1
Reputation: 682
You need to pass the event.
function deleteuploadfiles(id, **event**){
and also:
$( "your button" ).click(function( **event** ) {
deleteuploadfiles(id, event)
Upvotes: 4