Steven
Steven

Reputation: 1173

AJAX unsubmit form

I've made an ajax search filter which loads when a certain input has a value (this is the search query box):

 $("#filter").keyup(function(event){
var query = document.getElementById('query').value;
if(query!=""){
    $("#filter").submit();
}
else{
}
});

 $("#filter").submit(function(event) {
event.preventDefault();
$("#result").html('');
var values = $(this).serialize();
$.ajax({
    url: "filter_content.php",
    type: "get",
    data: values,
    success: function(data){
        $('#result').html(data);
    },
});
});

Is there a way to "unsubmit" the form when there is no value? So the ajax loaded content will disapeare instead of showing the content related to the last value (that wasn't blank)?

Thanks in advance!

Upvotes: 0

Views: 235

Answers (1)

sasikt
sasikt

Reputation: 5598

If you want to make the content disappear why don't you just change $('#result').html() to an empty or a default value. This could be done in the 'else' part of query check. There is nothing called unsubmit form. Hope that makes sense

Upvotes: 1

Related Questions