2016-03-22 11 views
0

Aşağıda html ve jquery kodlarım var, bir sonraki sayfada devam etmektense aynı sayfada gönder düğmesine basmak istiyorum. Ama bana hiçbir sonuç getirmiyor ve bir sonraki sayfaya gitmiyor. HTML kodunujquery web'i kullanarak aynı sayfadaki başka bir html'den görüntülenen gösterimi

<form id="create" action="/engine_search/search/" method="get"> 
          <input style="height:40px;" type="text" class="form-control" placeholder="Search" name="q"> 
          <center> 
          <input style="float:left; margin-left:150px;" type="submit" class="btn btn-default" value="Search"> 
           </center> 
         </form> 

jquery kodu:

<script> 
$(document).ready(function() { 
$('#create').submit(function() { // catch the form's submit event 
    $.ajax({ // create an AJAX call... 
     data: $(this).serialize(), // get the form data 
     type: $(this).attr('method'), // GET or POST 
     url: $(this).attr('action'), // the file to call 
     success: function(response) { // on success.. 
      $('#created').html(response); // update the DIV 
     } 
    }); 
    return false; // cancel original event to prevent form submitting 
}); 
}); 
</script> 

cevap

0
<input style="float:left; margin-left:150px;" type="submit" class="btn btn-default" value="Search" onclick="return SubmitFunction(this);"> 

JavaScript:

function SubmitFunction(thisId){ 
$.ajax({ // create an AJAX call... 
    data: $(thisId).serialize(), // get the form data 
    type: $(thisId).attr('method'), // GET or POST 
    url: $(thisId).attr('action'), // the file to call 
    success: function(response) { // on success.. 
     $('#created').html(response); // update the DIV 
    } 
}); 

return false; // cancel original event to prevent form submitting 

}

0

Sen hatalar için konsolu için event.preventDefault();

<script> 
$(document).ready(function() { 
$('#create').submit(function(event) { // catch the form's submit event 
    event.preventDefault(); 
    $.ajax({ // create an AJAX call... 
     data: $(this).serialize(), // get the form data 
     type: $(this).attr('method'), // GET or POST 
     url: $(this).attr('action'), // the file to call 
     success: function(response) { // on success.. 
      $('#created').html(response); // update the DIV 
     } 
    }); 
    return false; // cancel original event to prevent form submitting 
}); 
}); 
</script> 

bak kullanmalıdır. Bu yardımcı olabilir.

İlgili konular